Published on

Scoping Rules in Python

Authors

Generally speaking, variables, or names, in a program are valid in a limited context within a given program. They are called the "scopes" of those the variables. Roughly speaking, in many C-style languages, a lexical "block" in a program often defines, or is closely related to, the scope of the variables declared in the block.

Python is an exception. Python is one of the few commonly-used languages in which scope rules work rather differently than this common conventions.