class python def __init__ code example
Example 1: 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 2: init in python
class Employee():
no_of_leaves = 8
def __init__(self, aname, asalary, arole):
self.name = aname
self.salary = asalary
self.role = arole
def printdetail(self):
return f"Name is {self.name}. His salary is {self.salary}." \
f"and his role is {self.role}"