Besides member variables, classes can also have their own methods. For example:
class Square(object): def __init__(self, side): self.side = side def perimeter(self): return self.side * 4
perimeter() class method is identical to defining any other function, except that it is written inside of the
Square class definition.
Just like when we defined
__init__(), you need to provide
self as the first argument of any class method.
Car class, add a method named
Car that will reference the Car’s member variables to return the string,
"This is a [color] [model] with [mpg] MPG." You can use the
str() function to turn your
mpg into a string when creating the display string.
Replace the individual