Last active
April 5, 2018 21:35
-
-
Save messa/2a1a913c9ed0478ddfea3b5890819222 to your computer and use it in GitHub Desktop.
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
x = 11 | |
def f(): | |
x = 22 | |
print('uvnitr f:', x) | |
print(x) | |
f() | |
print(x) | |
# Výstup programu: | |
# | |
# 11 | |
# uvnitr f: 22 | |
# 11 | |
x = 11 | |
def f(): | |
print('uvnitr f:', x) | |
x = 22 | |
f() | |
# Tento program skončí chybou: | |
# UnboundLocalError: local variable 'x' referenced before assignment | |
# protože Python vidí, že ve funkci f je lokální proměnná x (že někde v té funkci se přiřazuje), | |
# ale v okamžiku provedení printu ještě není přiřazená (assigned) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment