Last active
August 29, 2015 14:05
-
-
Save tbillington/9584fe13760ada73ca63 to your computer and use it in GitHub Desktop.
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(starting_value): | |
count = starting_value | |
def counter(): | |
nonlocal count | |
count += 1 | |
return count | |
return counter | |
my_counter = make_counter(5) | |
my_counter() | |
> 6 | |
my_counter() | |
> 7 | |
my_counter() | |
> 8 | |
my_counter() | |
> 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment