Skip to content

Instantly share code, notes, and snippets.

@pknowledge
Created September 17, 2018 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pknowledge/8b9a13f238362d34596b79457af37b55 to your computer and use it in GitHub Desktop.
Save pknowledge/8b9a13f238362d34596b79457af37b55 to your computer and use it in GitHub Desktop.
Python Abstract Classes Example
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