You can use the abstract method decorator to declare a method abstract, and to declare a class abstract using one of three ways, depending upon which version of Python you are using.
If you are a Python 3.4+ user then you can use the following code:-
from abc import ABC, abstractmethod
class Abstract(ABC):
@abstractmethod
def foo(self):
pass
Python 3.0+ users can use the following way:-
from abc import ABCMeta, abstractmethod
class Abstract(metaclass=ABCMeta):
@abstractmethod
def foo(self):
pass
At last, the Python 2 user can use the following code:-
from abc import ABCMeta, abstractmethod
class Abstract:
__metaclass__ = ABCMeta
@abstractmethod
def foo(self):
pass
Whatever versions you are using you won't be able to instantiate an abstract class that has abstract methods, but will be able to instantiate a subclass that provides concrete definitions of those methods.
To know more about this you can have a look at the following video tutorial:-