Static methods
class Employee:
no_of_leaves = 8
def __init__(self, aname, asalary, arole):
self.name = aname
self.salary = asalary
self.role = arole
@classmethod
def from_str(cls, string):
'''params=string.split("-")
return cls(params[0],params[1],params[2])'''
return cls(*string.split("-"))
@staticmethod
def why(string):
print("what is u r name" + string)
karan = Employee.from_str("karan-25000-datascientist")
print(karan.salary)
karan.why(" boy")
Employee.why("boy") # u can access from class also
Comments
Post a Comment