What does the abstractmethod decorator in python does?
from abc import abstractmethod class Animal(object): @abstractmethod def walk(self): ''' data ''' pass @abstractmethod def talk(self): ''' data ''' pass class Duck(Animal): name = '' def __init__(self, name): print('duck created.') self.name = name def walk(self): print('walks') def talk(self): print('quack') obj = Duck('duck1') obj.talk() obj.walk() But if I comment the decorator, the code still works.
from abc import abstractmethod class Animal(object): def walk(self): ''' data ''' pass def talk(self): ''' data ''' pass class Duck(Animal): name = '' def __init__(self, name): print('duck created.') self.name = name def walk(self): print('walks') def talk(self): print('quack') obj = Duck('duck1') obj.talk() obj.walk() My question is why bother to use this decorator? I even delete some of the methods in Duck, say talk. Then it does not crash. I makes me not understand when do we need to use this abstractmethod?