Python LanguageVariable Scope and Binding

Syntax

  • global a, b, c
  • nonlocal a, b
  • x = something # binds x
  • (x, y) = something # binds x and y
  • x += something # binds x. Similarly for all other "op="
  • del x # binds x
  • for x in something: # binds x
  • with something as x: # binds x
  • except Exception as ex: # binds ex inside block