Created
February 16, 2021 07:33
-
-
Save arliber/a18ed878167274857105497a497f5f61 to your computer and use it in GitHub Desktop.
nonlocal #snippet #python
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 limit_5(): | |
remaining = 5 | |
def hello(name): | |
nonlocal remaining | |
if remaining <= 0: | |
raise TypeError("No more runs left!") | |
else: | |
remaining -= 1 | |
return f"Hello, {name}" | |
return hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment