Prev | Index | NextInheriting Behaviour From Other Classes
>>> class Person:
... def __init__(self, hair_colour="brown", eye_colour="blue",
... height_cm=170, weight_kg=70):
... self.hair_colour = hair_colour
... self.eye_colour = eye_colour
... self.height_cm = height_cm
... self.weight_kg = weight_kg
... def getHairColour(self):
... return self.hair_colour
... def getEyeColour(self):
... return self.eye_colour
...
>>> class Athlete(Person):
... def __init__(self, hair_colour, eye_colour,
... height_cm, weight_kg, sport):
... Person.__init__(self, hair_colour, eye_colour,
... height_cm, weight_kg)
... self.sport = sport
... def getSport(self):
... return self.sport
...
>>> wayne = Athlete("blonde", "blue", 180, 80, "hockey")
>>> wayne.getHairColour()
'blonde'
>>> wayne.getSport()
'hockey'
An Introduction To Python