Created
July 21, 2017 17:56
-
-
Save augustogoulart/37a427694392b45818b2984ade6bd1f5 to your computer and use it in GitHub Desktop.
Example of Pythons duck typing
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
""" | |
Example do demonstrate Python's Duck Typing | |
In [1]: from collections import Container | |
In [2]: Container.__abstractmethods__ | |
Out[3]: frozenset({'__contains__'}) | |
""" | |
import collections | |
class MyContainer: | |
def __contains__(self, item): | |
pass | |
my_container = MyContainer() | |
assert isinstance(my_container, collections.Container) | |
assert issubclass(MyContainer, collections.Container) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment