python def __init__(self) code example
Example 1: __init__ python
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("John", 36) // Object definition
print(p1.name)
print(p1.age)
Example 2: self and init in python
class Computer:
def __init__(self):
self.name= ("Pankaj")
self.age= 28
c1=Computer()
c2=Computer()
c1.name= "Garg"
print(c1.name)
print(c2.name)
Example 3: what is __init__ in python
my_variable = MyClass()
Example 4: import __init__.py
from . import *
from . import hello_world