Created
September 2, 2014 08:07
-
-
Save contee213/d4f168198d47aed79526 to your computer and use it in GitHub Desktop.
nonlocal test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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