Skip to content

Instantly share code, notes, and snippets.

@tmeissner tmeissner/
Last active Aug 29, 2015

What would you like to do?
Some experiments with closures in Python 3
def closure():
container = 0
def inc():
nonlocal container
container += 1
def get():
return container
def dec():
nonlocal container
container -= 1
def set(item):
nonlocal container
container = item
return inc, dec, set, get
if __name__ == "__main__":
inc, dec, set, get = closure()
for i in range(10):
for i in range(5):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.