Created
September 17, 2018 23:19
-
-
Save pknowledge/8b9a13f238362d34596b79457af37b55 to your computer and use it in GitHub Desktop.
Python Abstract Classes Example
This file contains 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 Shape(ABC): | |
@abstractmethod | |
def area(self): pass | |
@abstractmethod | |
def perimeter(self): pass | |
class Square(Shape): | |
def __init__(self, side): | |
self.__side = side | |
def area(self): | |
return self.__side * self.__side | |
def perimeter(self): | |
return 4 * self.__side | |
square = Square(5) | |
print(square.area()) | |
print(square.perimeter()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment