Quiz Dunder Methods And Overriding

 # Main 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


    def __pow__(self, other ):

        return self.salary ** other.salary


    def __floordiv__(self, other):

        return self.salary//other.salary

    def __mul__(self, other):

        return self.salary * other.salary




emp1 =Employee("Harry", 345, "Programmer")

emp2 =Employee("Rohan", 55, "Cleaner")


#1

print(emp1 ** emp2)


#2

print(emp1//emp2)


#3

print(emp1*emp2)


# Output:

#1 = 38023337028242770328467290130682661267517320614393508406079007784174954842038219727894921177043930468342214368249187828041613101959228515625

#2 = 6

#3 = 18975


Comments

Popular posts from this blog

Pickle Module

Python File IO Basics