Created
September 27, 2012 05:01
-
-
Save ChimeraCoder/3792248 to your computer and use it in GitHub Desktop.
Python Prototypical Inheritance Example
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
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