Skip to content

Instantly share code, notes, and snippets.

@pgainda
Created October 27, 2013 16:11
Show Gist options
  • Save pgainda/7184358 to your computer and use it in GitHub Desktop.
Save pgainda/7184358 to your computer and use it in GitHub Desktop.
Sometimes you'll be working with a derived class (or subclass) and realize that you've overwritten a method or attribute defined in that class' base class (also called a parent or superclass) that you actually need. Have no fear! You can directly access the attributes or methods of a superclass with Python's built-in super call.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment