Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python Prototypical Inheritance Example
from __future__ import print_function
class Foo(object):
apple = "red"
def __init__(self, banana):
self.banana = banana
tmp = Foo("yellow")
print(tmp.apple)
print(tmp.banana)
print(tmp.carrot)
'''
Output:
red
yellow
Traceback (most recent call last):
File "PythonRebindings.py", line 15, in <module>
print(tmp.carrot)
AttributeError: 'Foo' object has no attribute 'carrot'
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment