Skip to content

Instantly share code, notes, and snippets.

@duboisf
Created April 22, 2010 00:52
Show Gist options
  • Save duboisf/374657 to your computer and use it in GitHub Desktop.
Save duboisf/374657 to your computer and use it in GitHub Desktop.
simple closure example in python
class Value:
def __init__(self, val):
self.val = val
def invoker(x):
def closure(y):
print (x.val + y)
return closure
anObject = Value(5)
f = invoker(anObject)
f(1)
anObject.val = 10
f(1)
# prints:
# 6
# 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment