Creating Python classes

There’s our first object-oriented program! The class definition starts with the class keyword. This is followed by a name (of our choice) identifying the class, and is terminated with a colon.

Adding attributes

We can set arbitrary attributes on an instantiated object using the dot notation:

Initializing the object

Python has a constructor and an initializer
The Python initialization method is the same as any other method, except it has a special
name: __init__.
“this is a special method that the Python interpreter will treat as a special case”.

Open chat