View on GitHub

reading-notes

Python Scope

LINKS

Python Scope & the LEGB Rule: Resolving Names in Your Code

Understanding Scope

In programming, the scope of a name defines the area of a program in which you can unambiguously access that name, such as variables, functions, objects, and so on. A name will only be visible to and accessible by the code in its scope. Several programming languages take advantage of scope for avoiding name collisions and unpredictable behaviors. Most commonly, you’ll distinguish two general scopes:

  1. Global scope: The names that you define in this scope are available to all your code.

  2. Local scope: The names that you define in this scope are only available or visible to the code within the scope.

Back to Homepage