Created
June 6, 2012 19:53
-
-
Save jordanorelli/2884320 to your computer and use it in GitHub Desktop.
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
class Foo(object): | |
def __init__(self): | |
self.x = 0 | |
def __repr__(self): | |
return "<Foo x:%d>" % self.x | |
def add_x(self, x): | |
self.x += x | |
def add_x(foo, x): | |
foo.x += x | |
f = Foo() | |
print repr(f) | |
f.add_x(1) | |
print repr(f) | |
# I wouldn't, in practice, EVER do this in Python, even though it works: | |
add_x(f, 1) | |
print repr(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
outputs: