Created
May 18, 2020 08:14
-
-
Save ZhouYang1993/fdce2ff6793b6a3a257bdd87bf664556 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 | |
| class Animal(ABC): | |
| @abstractmethod | |
| def move(self): | |
| print('Animal moves') | |
| pass | |
| class Cat(Animal): | |
| def move(self): | |
| super().move() | |
| print('Cat moves') | |
| c = Cat() | |
| c.move() | |
| # Animal moves | |
| # Cat moves | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment