[Python]Inheritance and super() method

class Employee(object):

    """Models real-life employees!"""

    def __init__(self, employee_name):

        self.employee_name = employee_name

    def calculate_wage(self, hours):

        self.hours = hours

        return hours * 20.00

# Add your code below!

class PartTimeEmployee(Employee):

    def calculate_wage(self,hours):

        self.hours = hours

        return hours * 12.00

    def full_time_wage(self,hours):

        return super(PartTimeEmployee,self).calculate_wage(hours)

milton = PartTimeEmployee("Howe")

print milton.full_time_wage(10)






So when I called super() I need to simplify the argument which is PartTimeEmployee and it called the its father Employee and send the argument self, so I can use the calculate_wage to print the result.


In fact in Python 3.0, the super() is much more clearer to use, just  super().calculate_wage(hours) is okay to be used.






Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.