Skip to content

Instantly share code, notes, and snippets.

@tbillington
Last active August 29, 2015 14:05
Show Gist options
  • Save tbillington/9584fe13760ada73ca63 to your computer and use it in GitHub Desktop.
Save tbillington/9584fe13760ada73ca63 to your computer and use it in GitHub Desktop.
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