Skip to content

Instantly share code, notes, and snippets.

@emberian
Created November 11, 2012 01:14
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 emberian/4053259 to your computer and use it in GitHub Desktop.
Save emberian/4053259 to your computer and use it in GitHub Desktop.
def newCounter():
i = 0
def f():
nonlocal i
i += 1
return i
return f
c1 = newCounter()
print(c1()) # 1
print(c1()) # 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment