Abstraction & Encapsulation | Python Tutorials For Absolute Beginners In Hindi #59

Code as described/written in the video

class Employee:
    no_of_leaves = 8

    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}"

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

    def from_dash(cls, string):
        return cls(*string.split("-"))

    def printgood(string):
        print("This is good " + string)

harry = Employee("Harry", 255, "Instructor")
rohan = Employee("Rohan", 455, "Student")
karan = Employee.from_dash("Karan-480-Student")


Be the first person to comment!