2 Réponses
+ 4
__init__ is a constructor of a class, a special function that is used to initialize the newly created object. It is called when you do
obj=MyClass()
Also, note that it has two underscores both at beggining and end
0
#Example:
class food:
def __init__(self, color, name):
self.color = color
self.name = name
apple=food("red", "applename")
print(apple.color) #red
print(apple.name) #applename