Single and multiple inheritance in python
#
class Employee:
profession = "Networking"
def __init__(self, aname, asalary, arole):
self.name = aname
self.role = arole
self.salary = asalary
def printdetails(self):
return F"Name is {self.name} Salary is {self.salary} and role is {self.role}"
@classmethod
def change_profession(cls, newprofessional):
cls.profession = newprofessional
@classmethod
def from_str(cls, string):
# params = string.split("-")
# print(params)
# return cls(params[0],params[1],params[2])
# how to perform this in one line
return cls(*string.split("/"))
@staticmethod
def printgood(string):
print("This is good", string)
return string
class Programer(Employee):
def __init__(self, aname, asalary, arole, alanguage):
self.name = aname
self.salary = asalary
self.role = arole
self.language = alanguage
def printpro(self):
return f"The Programer's Name is {self.name} and salary is {self.salary} and role is {self.role} and the language are {self.language}"
umair = Employee("Umair", 344, "Instructor")
rehman = Employee.from_str("rehman/330/monitor")
# rehman.printgood("Umair")cls
# print (rehman.printdetails())
rehan = Programer("Rehan", 3534, "Progamer",["python"])
zain = Programer("Zain", 324, "Programer",["python","C++"])
print(zain.printpro())
Comments
Post a Comment