- All types in Python are classes
- Classes define the structure and behavior of an object
- Class is determined when an object is created
- Class is fixed for the lifetime of the object
- Classes are defined with the “class” keyword followed by a name with CamelCase syntax
- Class instances are created the same way you call a function
- Functions defined inside the class are instance methods
- They need to have an object instance “self” as a parameter
- To initialize new instances use the initializer. It is not a constructor.
__init__(self, OTHER, PARAMETERS)
- Instance attributes are created by assigning them
- Instance methods that help access implementation details are should be prefixed with an underscore (_)
- Established class invariants in the initializer
- Within objects, method calls still must be preceded with “self”
- Classes can inherit from their parents.
class Car: def engine_sound(self): print("vroom vroom") class FordMustang: ... >>>car = FordMustange() >>>car.engine_sound() vroom vroom