The Python Coding Stack • by Stephen Gruppetta • 179 implied HN points • 27 Oct 24
- In Python, each function has its own scope. This means a variable defined in a function can only be used inside that function, not outside.
- The LEGB rule helps Python find variables: it first looks in the Local scope, then in any Enclosing scopes, next in the Global scope, and finally in Built-in scope if it can't find the variable anywhere else.
- Namespaces are like containers for names in Python. They store the names of variables and their corresponding values, making it clear which variables are available in which parts of your code.