๐ŸŒ
Real Python
realpython.com โ€บ python-scope-legb-rule
Python Scope and the LEGB Rule: Resolving Names in Your Code โ€“ Real Python
July 16, 2026 - These dictionaries are the underlying mechanism that Python uses to store names under a specific scope. You can often access them through the .__dict__ attribute of the owning object. Note: To learn more about namespaces, check out the Namespaces in Python tutorial. For example, names that you define in a REPL session are stored in __main__.__dict__. Hereโ€™s an example: ... >>> name = "Pythonista" >>> dir() [ '__builtins__', '__doc__', '__loader__', ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_scope.asp
Python Scope
Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module ยท Remove List Duplicates Reverse a String Add Two Numbers ยท Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... A variable is only available from inside the region it is created. This is called scope...
Discussions

How to prevent "redefining name from outer scope" warning?
If it were def my_func(my_var): return my_var + 1 def main(): my_var = 5 print(my_func(my_var)) if __name__ == "__main__": main() then you'd be extra safe, since you've got a local and a local, completely unaware of each other. More on reddit.com
๐ŸŒ r/learnpython
11
3
December 6, 2023
How Does Scope in Python Work?
Only functions and classes introduce new scopes in Python. Control flow blocks share their "outer" scope. More on reddit.com
๐ŸŒ r/learnpython
11
2
January 18, 2021
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ scope-of-variables-python
Python Variable Scope And The LEGB Rule Explained | DataCamp
September 11, 2025 - Enclosing: any outer function scopes (for nested functions). Global: the moduleโ€™s top level (module namespace). Built-in: names defined by Python in builtins (for example, len, print).
๐ŸŒ
Real Python
realpython.com โ€บ lessons โ€บ built-in-scope
Inspecting the Built-in Scope (Video) โ€“ Real Python
So when you run the Python interpreter, these objects of the builtins module are inside of the built-in scope for you available right away. So for example, thatโ€™s why you can use functions like the print() function in line 4, 8, and 12 right away without importing anything, and Python knows what to do with it.
Published: November 1, 2022
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ python tutorial โ€บ scope in python
Scope in Python | Top 4 Types of Scope in Python with Examples
February 12, 2025 - For businesses looking to streamline their coding processes and avoid such issues, Python development services can offer tailored solutions to ensure efficient and error-free code implementation. ... # Built-in Scope from math import pi # pi = 'Not defined in global pi' def func_outer(): # pi = 'Not defined in outer pi' def inner(): # pi = 'not defined in inner pi' print(pi) inner() func_outer()
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Leyaa
leyaa.ai โ€บ codefly โ€บ learn โ€บ python โ€บ part-2 โ€บ python-builtin-scope
Built-in scope in Python - Syntax, Examples & Explanation | Leyaa.ai
Python automatically looks here if a name is not found in local or global scopes. Built-in scope is the last place Python looks for a name.
๐ŸŒ
Python Tutorial
pythontutorial.net โ€บ home โ€บ advanced python โ€บ python variable scopes
Python Variable Scopes
March 27, 2025 - In Python, scopes are nested. For example, local scopes are nested inside a module scope. Module scopes are nested inside the built-scope:
๐ŸŒ
DataFlair
data-flair.training โ€บ blogs โ€บ python-variable-scope
Python Variable Scope - Local, Global, Built-in, Enclosed - DataFlair
April 13, 2026 - In the first example printing the a and b, how the b can be printed, it is out side the function and it canโ€™t be accessed. Please explain. ... Hi Sai Thanks for commenting. a is local to func and cannot be read outside it, but we can read b from inside func. If we had to modify b inside func, we would first have to declare it global. ... Python built-in scope has all the names that are loaded into python variable scope when we start the interpreter.
Find elsewhere
๐ŸŒ
Real Python
realpython.com โ€บ lessons โ€บ builtin-scope
Breaking Down the Built-in Scope (Video) โ€“ Real Python
02:15 And since summer is coming up, Iโ€™ll redefine abs to 6. abs = 6. Because the built-in scope is the last scope to be checked by Python during name resolution, and you just created this variable in the global scope, ...
Published: May 27, 2025
๐ŸŒ
Real Python
realpython.com โ€บ videos โ€บ understanding-scope-python
Understanding Scope in Python (Video) โ€“ Real Python
For example, def my_func() and including argument names like arg1, arg2, up to argN. 01:54 And of course, through class definitions using the class keyword. Once you have a name defined, how does Python retrieve its associated object? 02:02 Ah, this is where the LEGB rule comes in. At any point in the execution of your program, there can be up to four active scopes: local, enclosing, global, and built-in.
Published: May 27, 2025
๐ŸŒ
TheAILearner
theailearner.com โ€บ tag โ€บ built-in-scope
Built-in scope โ€“ TheAILearner
September 26, 2018 - Letโ€™s see an example ... As we have no x in the local and enclosing scope, so Python checks the global scope and outputs 4 for both print x statements. Note: using too many global variables will generally lead to name conflicts and will likely lead to unwanted side effects. Built-in: Built-in means the function and variables that are already defined in python.
๐ŸŒ
Daily Dose of DS
blog.dailydoseofds.com โ€บ daily dose of data science โ€บ variable scope in python
Variable Scope in Python - by Avi Chawla
July 27, 2024 - The last in the priority order of scope resolution is built-in. These are variable names that are automatically loaded in the global Python scope when we: ... Some common examples include float, int, len, set, dict, range, str, zip, and more.
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ enclosing-scope
Enclosing scope in Python - Python Morsels
August 10, 2026 - While the global scope is ... anywhere within a Python process is within the built-in scope. For example, list, print, and ValueError are all in Python's built-in scope:...
๐ŸŒ
Medium
medium.com โ€บ @ruba_37171 โ€บ python-scopes-legb-3d030b41796a
Python Scopes (LEGB). There are four Python scopes: | by Ruba Dabbas | Medium
February 23, 2024 - The built-in scope is the scope that is loaded automatically when using Python, or executing a code, it includes the built-in names and objects that are already defined, with no need to redefine or import them from other libraries, such as:
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ python scope | types, legb rule, lifetime & more (+examples)
Python Scope | Types, LEGB Rule, Lifetime & More (+Examples)
February 4, 2025 - Built-in Scope: Predefined functions and objects in Python, such as print(), len(), and int(), available globally across all Python programs. Yes, you can access and modify global variables inside a function, but to modify them directly, you ...
๐ŸŒ
Technestx
technestx.github.io โ€บ python โ€บ py_scope.html
Python Scope Explained: Local, Global, Enclosing, Built-in Variables
The len() function is a built-in function in Python. It is accessible anywhere in the program, without having to import it. ... When Python tries to access a variable, it first looks for it in the local scope. If the variable is not found in the local scope, Python then looks for it in the ...
๐ŸŒ
Codefinity
codefinity.com โ€บ blog โ€บ Understanding-Scopes-in-Python-and-the-LEGB-Rule
Understanding Scopes in Python and the LEGB Rule
... Predefined Names: Includes Python's inbuilt functions, exceptions, and attributes. Universal Accessibility: Available throughout the Python program. ... The print function is an example of a built-in name, always accessible in Python programs.
๐ŸŒ
Medium
medium.com โ€บ @ahmedfgad โ€บ python-scopes-and-the-legb-rule-d37bf3277e2c
Python Scopes and the LEGB Rule. The scopes in Python defines at whichโ€ฆ | by Ahmed Gad | Medium
August 7, 2021 - B (Built-in): Built-in names in Python. Note that the LEGB rule not only defines the Python scopes but also the order in which the names are resolved. In this post, the local and global scopes are discussed. The tutorial has 2 main sections: ... Letโ€™s get started. ... Local scopes in Python are only created within functions. So, in order to call a name (e.g. variable) local, then it must be defined within a function. A for loop, for example, does not create scopes.
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ variable-scope-python
Python Variable Scope Guide & Its 4 Types (with LEGB rule)
March 17, 2023 - There are four primary scope types in Python: Local Scope: These variables are only available within the boundaries of the function or block in which they are specified. Enclosing Scope: This refers to variables defined in the local scope of an enclosing function that can be accessed by its nested functions. Global Scope: Variables defined outside any function or block have a global scope, accessible and modifiable by the whole program. Built-in Scope: The names of all the built-in modules are listed in the built-in scope which is available throughout the program.
๐ŸŒ
BtechSmartClass
btechsmartclass.com โ€บ python โ€บ Python_Tutorial_Python_Scope.html
Python Tutorials - Scope of variables | life time | Accessability
When we run the above example code, it produces the following output. When we have both a global variable and a local variable with the same name, then the global variable is hidden by the local variable. Inside the function, whenever we use that variable it always refers to the local variable only. In this situation, we use a built-in function globals( ) to access the global variable inside the function.