'How does the Python read the code? in what order in this case
class Animal:
def set_health(self, health):
print("Set in Animal")
class Carnivour(Animal):
def set_health(self, health):
super().set_health(health)
print("Set in Canivour")
class Mammal(Animal):
def set_health(self,health):
super().set_health(health)
print("Set in Mammal")
class Dog(Carnivour, Mammal):
def set_health(self, health):
super().set_health(health)
print("Set in dog")
dog = Dog()
dog.set_health(10)
I know that Python reads this structure of code from left to right. But I can not understand how it changes the output when we swap the Carnivour with Mammal in Dog() class.
Could someone explain me in details how it reads the code that the output prints
Set in animal
Set in Mammal
Set in Carnivour
Set in dog
When we have the Carnivour first in Dog() class
Thanks for help and understanding
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
