What does the following code output? from abc import ABC, abstractmethod class Animal(ABC): @abstractmethod def speak(self): … def describe(self): return f’I say {self.speak()}’ class Dog(Animal): def speak(self): return ‘woof’ print(Dog().describe())

Python Professional Hard

Python Professional — Hard

What does the following code output? from abc import ABC, abstractmethod class Animal(ABC): @abstractmethod def speak(self): … def describe(self): return f’I say {self.speak()}’ class Dog(Animal): def speak(self): return ‘woof’ print(Dog().describe())

Key points

  • Dog class implements the abstract speak method
  • describe method calls the speak method
  • Output includes the result of the speak method

Ready to go further?

Related questions