Professional Documents
Culture Documents
Oops
Oops
Oops
def walk(self):
print(f'This human is walking on {self.__legs} legs')
def eat(self):
print(f'This human is eating as it has {self.hands} hands')
@staticmethod
def pi():
return 3.141
def eat(self):
print(f'Indians love {self.food} foods')
Polymorphism in python defines methods in the child class that have the
same name as the methods in the parent class. In inheritance, the child
class inherits the methods from the parent class. Also, it is possible to
modify a method in a child class that it has inherited from the parent class.
In [151… ram.walk()
class Iquack(ABC):
@abstractmethod
def quacking(self):
pass
class Ifly(ABC):
@abstractmethod
def flying(self):
pass
class normalQuack(Iquack):
def quacking(self):
class noQuack(Iquack):
def quacking(self):
return None
class lowFly(Ifly):
def flying(self):
return 'low fly'
class noFly(Ifly):
def flying(self):
return None
def flying(self):
return self.fly.flying()
def quacking(self):
return self.quack.quacking()
In [24]: johny.flying()
In [ ]: