Single Inheritance

 Main Syntax :

class Programmer(Employee):
def __init__(self, aname, asalary, arole, alanguages):
self.name = aname
self.salary = asalary
self.role = arole
self.languages = alanguages

def printprog(self):
print(f"Name of programmer is {self.name}. Salary is {self.salary}. Role is {self.role}. Languages known are {self.languages}.")


harry = Employee("Harry", 255, "Instructor")
rohan = Employee("Rohan", 455, "Student")

shubham = Programmer("Shubham", 555, "Programmer", ['Python, C++'])
karan = Programmer("Karan", 777, "Programmer", "Python, Java")

print(karan.printprog())

Full Code:
class Employee:
no_of_leaves = 89

def __init__(self, aname, asalary, arole):
self.name = aname
self.salary = asalary
self.role = arole

def printdetails(self):
return f"The Name is {self.name}. Salary is {self.salary} and role is {self.role}"

@classmethod
def change_leaves(cls, newleaves):
cls.no_of_leaves = newleaves

@classmethod
def from_str(cls, string):
return cls(*string.split("-"))

@staticmethod
def print_good(string):
print("This is good " + string)

class Programmer(Employee):
def __init__(self, aname, asalary, arole, alanguages):
self.name = aname
self.salary = asalary
self.role = arole
self.languages = alanguages

def printprog(self):
print(f"Name of programmer is {self.name}. Salary is {self.salary}. Role is {self.role}. Languages known are {self.languages}.")


harry = Employee("Harry", 255, "Instructor")
rohan = Employee("Rohan", 455, "Student")

shubham = Programmer("Shubham", 555, "Programmer", ['Python, C++'])
karan = Programmer("Karan", 777, "Programmer", "Python, Java")

print(karan.printprog())

Comments

Popular posts from this blog

Practice Execise 3

Pickle Module