+ 1
please explain me the use of __init__ !! im not getting it!! please provide an example also and tell me why is it necessary!!
please explain me the use of __init__ !! im not getting it!! please provide an example also and tell me why is it necessary!!
3 Respostas
0
Use the __init__() function to assign values to object properties, or other operations that are necessary to do when the object is being created:
Example
Create a class named Person, use the __init__() function to assign values for name and age:
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("John", 36)
//John
//36
Note: The __init__() function is called automatically every time the class is being used to create a new object.
0
thank you enemy!!
0
hey john answer my new question