Skip to content

Instantly share code, notes, and snippets.

@messa
Last active April 5, 2018 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save messa/2a1a913c9ed0478ddfea3b5890819222 to your computer and use it in GitHub Desktop.
Save messa/2a1a913c9ed0478ddfea3b5890819222 to your computer and use it in GitHub Desktop.
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