Skip to content

Instantly share code, notes, and snippets.

@AntiKnot
Created December 17, 2019 06:39
Show Gist options
  • Select an option

  • Save AntiKnot/d55ea767e443f0147252e94140f05a5e to your computer and use it in GitHub Desktop.

Select an option

Save AntiKnot/d55ea767e443f0147252e94140f05a5e to your computer and use it in GitHub Desktop.
import abc
class Animal(metaclass=abc.ABCMeta):
@abc.abstractmethod
def screaming(self):
'Return when animal screaming the sound hear likes'
return NotImplemented
@abc.abstractmethod
def walk(self, x, y):
'Make animal walk to position (x, y).'
return NotImplemented
class Dog(Animal):
pass
Dog()
"""
TypeError: Can't instantiate abstract class Dog with abstract methods screaming, walk
"""
class Animal(object):
def screaming(self):
'Return when animal screaming the sound hear likes'
return NotImplemented
def walk(self, x, y):
'Make animal walk to position (x, y).'
return NotImplemented
class Dog(Animal):
pass
Dog()
"""
Dog not NotImplemented screaming walk method, but can instantiate
"""
@AntiKnot
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment