Skip to content

Instantly share code, notes, and snippets.

@judy2k
Last active August 29, 2015 14:07
Show Gist options
  • Save judy2k/01b8d19434090bce4df3 to your computer and use it in GitHub Desktop.
Save judy2k/01b8d19434090bce4df3 to your computer and use it in GitHub Desktop.
Writeable Closures
#!/usr/bin/env python
def outer():
i = [0]
def inner():
i[0] += 1
print i[0]
return inner
f = outer()
f()
f()
#!/usr/bin/env python3.4
def outer(i):
def inner():
nonlocal i
i += 1
print(i)
return inner
f = outer(4)
f()
f()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment