class Animal:
def __init__(self, legs, name):
self.eyes = 2
self.legs = legs
self.name = name
def breathe(self):
print("Inhale, exhale")
def __str__(self):
return f"I'm an animal with {self.legs} legs, I'm also called {self.name}"
class Fish(Animal):
def __init__(self, legs, name):
super(Fish, self).__init__(legs, name)
def swim(self):
print("Swimming")
def __str__(self):
return f"I'm a fish with {self.legs} legs, I'm also called {self.name}"
fish = Fish(0, "Nemo")
fish.breathe()
fish.swim()
print(fish)
# this is the class which will become
# the super class of "Subclass" class
class Class():
def __init__(self, x):
print(x)
# this is the subclass of class "Class"
class SubClass(Class):
def __init__(self, x):
# this is how we call super
# class's constructor
super().__init__(x)
# driver code
x = [1, 2, 3, 4, 5]
a = SubClass(x)