Which object does this "self" refer to?


#1

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

class PartTimeEmployee(Employee):
def calculate_wage(self, hours):
self.hours = hours
return hours * 12.00

def full_time_wage(self, hours):
self.hours = hours
return super(PartTimeEmployee, self).calculate_wage(hours)

employee1 = PartTimeEmployee(“Milton”)

print employee1.full_time_wage(10)

My question is about this bit:

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

Is the “self” in this part referring to Employee or PartTimeEmployee?


#2

Neither, those are types. (types are also objects, but probably not what you meant)

self is the first argument given to your method, that’s what it refers to. It is the object that your method was called on


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.