Created
November 21, 2019 09:11
-
-
Save icarrr/c36db63a63206c5d342d3516169f3ded to your computer and use it in GitHub Desktop.
Access a function variable outside the function without using “global”
This file contains 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 hi(): | |
# other code... | |
hi.bye = 42 # Create function attribute. | |
sigh = 10 | |
hi() | |
print(hi.bye) # -> 42 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment