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

Popular posts from this blog

Steps taken by a compiler to execute a C program

Tokens in C

Variables and Data Types in C