IT 117: Intermediate Scripting
Quiz 8 Answers

  1. What do you call the special class of methods that do things like provide a string representation of an object and convert one data type into another?
    magic methods
  2. What is the name of the method that will return a string representation of an object?
    __str__
  3. What is the name of the boolean method that allows you to test whether one object is equal to another?
    __eq__
  4. What do you call the feature of Python that allows you to construct a new class based on another class?
    inheritance
  5. If you want to use a class representing one thing as the basis for a class representing another thing, what must the relationship between the two things be?
    an is a relationship
  6. If one class is used to create another class, what do you call the new class?
    a subclass
  7. If one class is used to create another class, what do you call the original class?
    a superclass
  8. If I wanted to define the class Cat which is a based upon the class Pet, what would I write for a class header?
    class Cat(Pet)
  9. Let's say that the constructor for the Pet class takes only 1 argument, the name of the pet. Write the Python statement you would use to call the Pet constructor within the Cat constructor code.
    Pet.__init__(self, name)
  10. If I wanted to call the __str__ method of the Pet class inside a method in the Cat class, what expression would I write?
    super().__str__()