Classes - Advanced Techniques Flashcards

1
Q

How do you call a method from the parent class in Python using super()

A

class Animal:
def speak(self):
return “Animal sound”

class Dog(Animal):
def speak(self):
return super().speak() + “ + Bark”

pet = Dog()
print(pet.speak()) # Output: Animal sound + Bark

Use super().method_name() inside the subclass to access the parent’s version

How well did you know this?
1
Not at all
2
3
4
5
Perfectly