August 2019
Beginner
482 pages
12h 56m
English
As we mentioned already, this method represents the initialization of a class instance. It is called any time you initialize a class. It is usually stored to add some properties you're passing upon initialization, and running any kind of initialization setup. During initialization, you can call any other method of the object. Here is an example:
class Animal: def __init__(self, age, diet): self.age = age self.diet = diet
In this example, we created an Animal class and stored two attributes, age, and diet, upon initialization.
Read now
Unlock full access