00:00:00 multiple inheritance
00:03:29 multilevel inheritance
00:05:03 attributes
class Animal:
def __init__(self, name):
self.name = name
def eat(self):
print(f"{self.name} is eating")
def sleep(self):
print(f"{self.name} is sleeping")
class Prey(Animal):
def flee(self):
print(f"{self.name} is fleeing")
class Predator(Animal):
def hunt(self):
print(f"{self.name} is hunting")
class Rabbit(Prey):
pass
class Hawk(Predator):
pass
class Fish(Prey, Predator):
pass
rabbit = Rabbit("Bugs")
hawk = Hawk("Tony")
fish = Fish("Nemo")
00:03:29 multilevel inheritance
00:05:03 attributes
class Animal:
def __init__(self, name):
self.name = name
def eat(self):
print(f"{self.name} is eating")
def sleep(self):
print(f"{self.name} is sleeping")
class Prey(Animal):
def flee(self):
print(f"{self.name} is fleeing")
class Predator(Animal):
def hunt(self):
print(f"{self.name} is hunting")
class Rabbit(Prey):
pass
class Hawk(Predator):
pass
class Fish(Prey, Predator):
pass
rabbit = Rabbit("Bugs")
hawk = Hawk("Tony")
fish = Fish("Nemo")
- Category
- Bro Code
- Tags
- Python tutorial, python course, python programming

Be the first to comment