Mundo em Python

Heranças em Python

 


class Animal:
def __init__(self):
self.num_eyes = 2

def breathe(self):
print("Inhale, Exhale")
class Fish(Animal):
def __init__(self):
super().__init__() # Call the __init__ method of the superclass

def swim(self):
print("Moving in water")
nemo = Fish() nemo.swim()
nemo.breathe()
print(nemo.num_eyes) # Output Moving in water
Inhale, Exhale
2

 


 



class Fish(Animal):
def __init__(self):
super().__init__() # Call the __init__ method of the superclass

def breathe(self):
super().breathe()
print("doing this underwater.")
def swim(self):
print("Moving in water")
nemo = Fish()
nemo.breathe()

#Output


Inhale, Exhale
doing this underwater.

0