Created
May 18, 2020 07:52
-
-
Save ZhouYang1993/17351c15142452bb7a8f18d56260c3a8 to your computer and use it in GitHub Desktop.
Abstract classes in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #### example 1 | |
| class Animal(ABC): | |
| @abstractmethod | |
| def move(self): | |
| pass | |
| a = Animal() | |
| # TypeError: Can't instantiate abstract class Animal with abstract methods move | |
| #### example 2 | |
| class Animal(): | |
| @abstractmethod | |
| def move(self): | |
| pass | |
| a = Animal() # No errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment