Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created June 6, 2012 19:53
Show Gist options
  • Save jordanorelli/2884320 to your computer and use it in GitHub Desktop.
Save jordanorelli/2884320 to your computer and use it in GitHub Desktop.
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)
@jordanorelli
Copy link
Author

outputs:

<Foo x:0>
<Foo x:1>
<Foo x:2>

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