Skip to content

Instantly share code, notes, and snippets.

@contee213
Created September 2, 2014 08:07
Show Gist options
  • Save contee213/d4f168198d47aed79526 to your computer and use it in GitHub Desktop.
Save contee213/d4f168198d47aed79526 to your computer and use it in GitHub Desktop.
nonlocal test
def make_counter(init):
i = init
def count():
nonlocal i
i = i + 1
print(i)
return count
if __name__ == '__main__':
c = make_counter(2)
c()
c()
c()
c = make_counter(100)
c()
c()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment