Loading…
A subclass inherits from a parent class:
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
return "Some sound"class Dog(Animal): # Dog inherits from Animal
def speak(self):
return f"{self.name} says Woof!"
dog = Dog("Buddy")
print(dog.speak()) # Buddy says Woof!
Expense with description and amountTravelExpense that inherits from Expensedestination attributeDownloading Python… (one-time, ~10 MB)
This runs entirely in your browser and is cached for next time.