Last active
May 18, 2020 08:00
-
-
Save ZhouYang1993/68e9cd2525f827710718a7667e5d88ab 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
| from abc import ABC, abstractmethod | |
| ### 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(): # still can be instantiated | |
| @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