This Looks Like a Job For...(DOUBT)


#1



The code compiled great, but replacing the LINE 16 with args self and hours do not compile like
return super(PartTimeEmployee, self).calculate_wage(self, hours)

1. class Employee(object):
2.     """Models real-life employees!"""
3.     def __init__(self, employee_name):
4.         self.employee_name = employee_name

5.     def calculate_wage(self, hours):
6.         self.hours = hours
7.         return hours * 20.00

8. # Add your code below!
9. class PartTimeEmployee(Employee):
10.     
11.     def calculate_wage(self, hours):
12.         self.hours = hours
13.         return hours * 12.00
14.         
15.     def full_time_wage(self, hours):
16.         return super(PartTimeEmployee, self).calculate_wage(hours)
17.         
18. milton = PartTimeEmployee("milton")
19. print milton.full_time_wage(10)


#2

self is an implicit argument in Python referring to the object that called the method. So, for example:

obj = PartTimeEmployee("milton")
obj.calculate_wage(10)

Here, the self argument in calculate_wage method will refer to obj. Note that while calling the method you only had to pass the hours argument. You had not passed the self argument, it was automatically assigned a value.

Can you now answer your own question? :wink:


#3

hello , may I ask you a question
if we define a method ,we should add self(like para11), but if we call to the method,we should not add self (like para16)? Is that true? why

  1. class PartTimeEmployee(Employee):
  2. def calculate_wage(self, hours):
  3. self.hours = hours
  4. return hours * 12.00
  5. def full_time_wage(self, hours):
  6. return super(PartTimeEmployee, self).calculate_wage(hours)

#4

Yes, you are right. self should not be included when calling the method. The self parameter is an implicit argument in Python, meaning that it is automatically assigned a value by the interpreter. The value is a reference to the object that called the method.

Hope it helps! :slight_smile:


#5

Got it.Thank you very much.:grin: