Intro to Classes 14, what is happening?


#1

I got the correct output for this exercise (Intro to Classes: 14. This Looks Like a Job For...) but I have no idea what I did. Could someone explain to me what the syntax for using a super() function is? Why do I put PartTimeEmployee before self? Why do I say hours? What would go in these spaces in another situation? Thanks in advance :slight_smile: my code is below:

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("Milton")
print milton.full_time_wage(10)

#2

super is used to access inherited behaviour that you've overridden.

You're specifying hours because the overridden calculate_wage takes hours as an argument.

Because the order of the arguments need to match the parameters of what you're calling, it's the order that decides which value is assigned to which parameter. You can ask the same question for any function that takes more than one argument.
As for why you need to provide that information, that's because super needs to know the context that it is used in.