Skip to content

Instantly share code, notes, and snippets.

@illume
Created October 21, 2011 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illume/1303258 to your computer and use it in GitHub Desktop.
Save illume/1303258 to your computer and use it in GitHub Desktop.
# closures in python
# closures in python
def f0(x):
closed_var = x + 1
def fclose():
return closed_var
return fclose
a_closure = f0(9)
# the 'closed_var' is now x + 1 == 10
assert(a_closure() == 10)
assert(a_closure() == 10)
a_closure2 = f0(20)
# the 'closed_var' is now x + 1 == 21
assert(a_closure2() == 21)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment