less than 1 minute read

All classes have a function called init(), is always executed when class is initiated. The method is useful to do any initialization you want to do with your object.

Example:

class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age

p = Person("Ellie", 30)

print(p.name)
print(p.age) 

#Output:
Ellie
30

References

Example

Definition