scope
The region of a program where a name can be seen and used.
In more detail
Python looks a name up in the local scope of the current function, then any enclosing functions, then the module's global scope, and finally the built-ins. Assignment inside a function makes a local name unless declared global.
Related terms
- local variable — A variable that exists only inside one function call and cannot be seen or changed from outside it.
- global variable — A variable defined at the top level of a program or module, shared by all the code in that process.
- Python namespace — A mapping from names to objects; each module, function call and class has its own, which is why the same name can mean different things in different places.
Taught in
- Local Scope And Global Constants — Hands-on Python: Complete Video Course & Book
- Functions, Return Values And Recursion — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Parameters, Arguments And Scope — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Functions And Exceptions Sprint — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Twelve Traps, One Shape Each — PCEP Certified Entry-Level Python Programmer (PCEP-30-02) Exam Prep
- Modules Sprint — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep
- Methods And The self Parameter — PCAP Certified Associate in Python Programming (PCAP-31-03) Exam Prep