External Exam Download Resources Web Applications Games Recycle Bin

Inheritance

inheritance.py

class Animal: #parent Class
  def __init__(self, age=0):
    self.age = age

class Fish(Animal): #inherits Animal
  def swim(self):
      print("gone swimming.")

fido = Animal() 
dori = Fish(2)
print(dori.age) #2
dori.swim() #gone swimming