{"id":100310,"date":"2026-02-05T17:09:07","date_gmt":"2026-02-05T11:39:07","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=100310"},"modified":"2026-04-01T10:59:37","modified_gmt":"2026-04-01T05:29:37","slug":"what-is-namespace-in-python","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/what-is-namespace-in-python\/","title":{"rendered":"Understanding Namespace and Scope in Python: A Complete Beginner\u2019s Guide"},"content":{"rendered":"\n<p>Imagine you have a notebook where you write down phone numbers. You might save your best friend as \u201cAlex,\u201d your colleague as \u201cAlex,\u201d and your cousin as \u201cAlex.\u201d Without additional context, calling the right Alex would be impossible. To avoid confusion, you probably organize them as Alex (Friend), Alex (Office), and Alex (Cousin).<\/p>\n\n\n\n<p>Python faces a similar problem.<\/p>\n\n\n\n<p>In programming, we constantly create names for variables, functions, classes, and objects. As programs grow larger, the chances of name conflicts increase. This is where namespaces come into play. A namespace helps Python understand which name you are referring to and where it belongs.<\/p>\n\n\n\n<p>In this blog, we\u2019ll explore what a namespace and scope in Python is, why it is important, and how Python manages names efficiently. Along the way, we\u2019ll also look at tuple in python and tuple in python with examples, connecting these concepts naturally so beginners can see how everything fits together.<\/p>\n\n\n\n<p><strong>Quick answer:<\/strong><\/p>\n\n\n\n<p>In Python, a namespace stores variable names and their values, while scope defines where those variables can be accessed. Python follows the LEGB rule to find variables. Using immutable data like tuple in python helps keep values safe across scopes, as shown in many tuple in python with example cases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Namespace and Scope in Python<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">What Is a Namespace in Python?<\/h2>\n\n\n\n<p>In Python a namespace is an object that contains a mapping between names and objects.<\/p>\n\n\n\n<p>In simpler terms:<\/p>\n\n\n\n<ul>\n<li>A name is such as a <a href=\"https:\/\/www.guvi.in\/blog\/do-you-know-how-to-create-variables-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">variable <\/a>name, function name or class name.<\/li>\n\n\n\n<li>An object is the real information that is held in memory (numbers, strings, lists, tuples, functions etc.).<\/li>\n<\/ul>\n\n\n\n<p>The namespaces in Python help to manage names and eliminate confusion in case the same name is written in several locations.<\/p>\n\n\n\n<p>Namespace Conflict Without Name Examples:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>x = 10<br>print(x)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>In this case, x denotes a single object (10). No confusion exists.<\/p>\n\n\n\n<p>But what about the occasions when the same name is used more than once? Namespace is where namespaces are necessary.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Do We Need Namespaces?<\/h2>\n\n\n\n<p>Namespace addresses three significant issues:<\/p>\n\n\n\n<ul>\n<li>Avoid name collisions<\/li>\n\n\n\n<li>Improve code organization<\/li>\n\n\n\n<li>Create large programs manageable.<\/li>\n<\/ul>\n\n\n\n<p>Consider this example:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>def show():<br>&nbsp; &nbsp; x = 5<br>&nbsp; &nbsp; print(x)<br><br>x = 20<br>show()<br>print(x)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>5<br>20<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Although x is used twice, <a href=\"https:\/\/www.guvi.in\/blog\/how-to-install-python-in-visual-studio-code\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python<\/a> is aware of which one to take. This is due to the existence of each x in a dissimilar namespace.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Understanding Namespaces with a Real-Life Analogy<\/h2>\n\n\n\n<p>Think of namespaces as labeled storage boxes.<\/p>\n\n\n\n<ul>\n<li>Each box has its own items<\/li>\n\n\n\n<li>Products in one box do not clash with products in another box.<\/li>\n\n\n\n<li>The right box label is necessary and to find the right item.<\/li>\n<\/ul>\n\n\n\n<p>On the same note, Python has namespaces that help in the safe storage and retrieval of variables.<\/p>\n\n\n\n<p><strong><em>Also read: <\/em><\/strong><a href=\"https:\/\/www.guvi.in\/blog\/how-to-use-global-variables-inside-a-function-learn-python-with-examples\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>How To Use Global Variables Inside A Function In Python?<\/em><\/strong><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Namespace types in Python<\/h2>\n\n\n\n<p>There are four types of python namespaces:<\/p>\n\n\n\n<ul>\n<li>Built-in Namespace<\/li>\n\n\n\n<li><a href=\"https:\/\/www.f5.com\/glossary\/global-namespace\" target=\"_blank\" rel=\"noreferrer noopener\">Global Namespace<\/a><\/li>\n\n\n\n<li>Local Namespace<\/li>\n\n\n\n<li>Enclosing Namespace<\/li>\n<\/ul>\n\n\n\n<p>We shall take them one step at a time.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1200\" height=\"630\" src=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/04\/Types-of-Plots-in-Seaborn-in-Python-1200x630.png\" alt=\"\" class=\"wp-image-105284\" srcset=\"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/04\/Types-of-Plots-in-Seaborn-in-Python-1200x630.png 1200w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/04\/Types-of-Plots-in-Seaborn-in-Python-300x158.png 300w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/04\/Types-of-Plots-in-Seaborn-in-Python-768x403.png 768w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/04\/Types-of-Plots-in-Seaborn-in-Python-1536x806.png 1536w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/04\/Types-of-Plots-in-Seaborn-in-Python-2048x1075.png 2048w, https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/04\/Types-of-Plots-in-Seaborn-in-Python-150x79.png 150w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" title=\"\"><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Built-in Namespace<\/strong><\/h3>\n\n\n\n<p>The built-in namespace has all those names that python provides in default.<\/p>\n\n\n\n<p>Examples include:<\/p>\n\n\n\n<ul>\n<li>print()<\/li>\n\n\n\n<li>len()<\/li>\n\n\n\n<li>int()<\/li>\n\n\n\n<li>tuple()<\/li>\n<\/ul>\n\n\n\n<p>These there are always ready to be defined without one having to define them.<\/p>\n\n\n\n<p><strong>Example<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>numbers = [1, 2, 3]<br>print(len(numbers))<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Here:<\/p>\n\n\n\n<ul>\n<li>print and len belong to built-in namespace.<\/li>\n\n\n\n<li>numbers is in the global space.<\/li>\n<\/ul>\n\n\n\n<p><strong><em>Also read: <\/em><\/strong><a href=\"https:\/\/www.guvi.in\/blog\/how-to-create-virtual-environment-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>How To Create Virtual Environment In Python<\/em><\/strong><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Global Namespace<\/strong><\/h3>\n\n\n\n<p>All variables and functions defined on the top level of a script or module are added to the global namespace.<\/p>\n\n\n\n<p>Major Features of the Global Namespace:<\/p>\n\n\n\n<ul>\n<li>Any variables identified here are available anywhere in the file.<\/li>\n\n\n\n<li>Global variables can be read in functions.<\/li>\n\n\n\n<li>The global variables within functions can only be modified with special permission (global keyword)<\/li>\n<\/ul>\n\n\n\n<p>Example<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>x = 100<br><br>def display():<br>&nbsp; &nbsp; print(x)<br><br>display()<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>In this case, the namespace of x belongs to the global namespace and can be used within the function.<\/p>\n\n\n\n<p><strong><em>Also read: <\/em><\/strong><a href=\"https:\/\/www.guvi.in\/blog\/what-is-a-data-type-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>What Is a Data Type in Python?<\/em><\/strong><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Local Namespace<\/strong><\/h3>\n\n\n\n<p>Local namespace is generated when a function is invoked. There are names defined within that function.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>def demo():<br>&nbsp; &nbsp; y = 50<br>&nbsp; &nbsp; print(y)<br><br>demo()<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>y exists only inside demo()<\/p>\n\n\n\n<p>Beyond the role, y is nonexistent.<\/p>\n\n\n\n<p><strong><em>Also read: <\/em><\/strong><a href=\"https:\/\/www.guvi.in\/blog\/books-vs-courses-which-is-better-for-learning-python\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>Books vs Courses: Which Is Better for Learning Python from Scratch?<\/em><\/strong><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Enclosing Namespace<\/strong><\/h3>\n\n\n\n<p>The enclosing namespace is found in nested functions.<\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>def outer():<br>&nbsp; &nbsp; z = 30<br>&nbsp; &nbsp; def inner():<br>&nbsp; &nbsp; &nbsp; &nbsp; print(z)<br>&nbsp; &nbsp; inner()<br><br>outer()<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Here:<\/p>\n\n\n\n<ul>\n<li>z is neither local nor global to inner.<\/li>\n\n\n\n<li>It is a part of enclosing namespace.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Comparison Table<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Namespace Type<\/strong><\/td><td><strong>Where It Exists<\/strong><\/td><td><strong>Example<\/strong><\/td><\/tr><tr><td>Built-in<\/td><td>Provided by Python<\/td><td>print(), len()<\/td><\/tr><tr><td>Global<\/td><td>Top level of script<\/td><td>x = 100<\/td><\/tr><tr><td>Local<\/td><td>Inside a function<\/td><td>y = 50<\/td><\/tr><tr><td>Enclosing<\/td><td>Outer function<\/td><td>z in nested functions<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong><em>Also read: <\/em><\/strong><a href=\"https:\/\/www.guvi.in\/blog\/what-is-a-python-library\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>What is a Python Library? A Simple Guide for Complete Beginners<\/em><\/strong><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Scope in Python?<\/h2>\n\n\n\n<p>If a namespace answers the question \u201cwhere does a variable live?\u201d, then scope answers the question \u201cwhere can I use this variable?\u201d.<\/p>\n\n\n\n<p>In other words, scope defines the region of a program where a variable name is accessible and valid.<\/p>\n\n\n\n<p>Scope is the Python variable that informs us of the variables that are visible at a point of the code.<\/p>\n\n\n\n<p>It would be best to understand this as implying that a variable may be present anywhere in your program (within a namespace) yet Python will not allow you to access or manipulate it unless your code is in the scope of the variable.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Feature<\/strong><\/td><td><strong>Namespace<\/strong><\/td><td><strong>Scope<\/strong><\/td><\/tr><tr><td>Purpose<\/td><td>Stores variable names<\/td><td>Controls accessibility<\/td><\/tr><tr><td>Focus<\/td><td>Storage<\/td><td>Visibility<\/td><\/tr><tr><td>Lifetime<\/td><td>Depends on context<\/td><td>Depends on code structure<\/td><\/tr><tr><td>Example<\/td><td>Global namespace<\/td><td>Local function scope<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong><em>Also read: <\/em><\/strong><a href=\"https:\/\/www.guvi.in\/blog\/what-is-python-encapsulation\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>Master Python Encapsulation in One Hour: From Basics to Pro<\/em><\/strong><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Python\u2019s LEGB Rule<\/h2>\n\n\n\n<p>Python follows a strict order to look up variable names, called the LEGB Rule:<\/p>\n\n\n\n<ul>\n<li>L \u2013 Local<\/li>\n\n\n\n<li>E \u2013 Enclosing<\/li>\n\n\n\n<li>G \u2013 Global<\/li>\n\n\n\n<li>B \u2013 Built-in<\/li>\n<\/ul>\n\n\n\n<p>Python searches for a variable in this exact order.<\/p>\n\n\n\n<p>Example to Understand LEGB<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>x = (1, 2, 3)&nbsp; # tuple in python (global)<br><br>def outer():<br>&nbsp; &nbsp; x = (4, 5, 6)<br><br>&nbsp; &nbsp; def inner():<br>&nbsp; &nbsp; &nbsp; &nbsp; print(x)&nbsp; # Which x?<br>&nbsp; &nbsp;<br>&nbsp; &nbsp; inner()<br><br>outer()<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>(4, 5, 6)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Python finds x in the enclosing scope before checking the global scope.<\/p>\n\n\n\n<p>This is a classic tuple in python with example demonstrating how scope resolution works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Local Scope<\/h2>\n\n\n\n<p>Variables defined inside a function belong to the local scope.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>def calculate():<br>&nbsp; &nbsp; values = (10, 20, 30)<br>&nbsp; &nbsp; print(values)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Trying to access values outside the function will raise an error.<\/p>\n\n\n\n<p>Why use tuples here?<\/p>\n\n\n\n<ul>\n<li>Tuples prevent accidental modification<\/li>\n\n\n\n<li>Ideal for grouped constant data<\/li>\n<\/ul>\n\n\n\n<p>This is another practical tuple in python with example showing safe local data usage.<\/p>\n\n\n\n<p><strong><em>Also read: <\/em><\/strong><a href=\"https:\/\/www.guvi.in\/blog\/what-is-python-keywords\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>Python Keywords Guide: What Every Developer Must Know (2026)<\/em><\/strong><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Global Scope<\/h2>\n\n\n\n<p>Global variables are defined outside all functions.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>data = (100, 200, 300)<br><br>def show_data():<br>&nbsp; &nbsp; print(data)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Here, data is accessible inside the function because it exists in the global scope.<\/p>\n\n\n\n<p><strong>Important Warning<\/strong>:<\/p>\n\n\n\n<p>Avoid modifying global variables directly it makes debugging harder. Use tuple in python if the data should remain unchanged.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Enclosing Scope (The Often Ignored One)<\/h2>\n\n\n\n<p>The enclosing scope exists in nested functions.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>def outer():<br>&nbsp; &nbsp; items = (1, 2)<br><br>&nbsp; &nbsp; def inner():<br>&nbsp; &nbsp; &nbsp; &nbsp; print(items)<br><br>&nbsp; &nbsp; inner()<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>items is not local to inner, but Python still finds it due to the enclosing scope.<\/p>\n\n\n\n<p><strong><em>Also read: <\/em><\/strong><a href=\"https:\/\/www.guvi.in\/blog\/top-python-data-science-interview-questions\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>Top 40 Python Data Science Interview Questions<\/em><\/strong><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Built-in Scope<\/h2>\n\n\n\n<p>If Python can\u2019t find a variable in local, enclosing, or global scopes, it checks the built-in scope.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>numbers = (1, 2, 3)<br>print(len(numbers))<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>len() comes from the built-in namespace.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The global Keyword<\/h2>\n\n\n\n<p>To modify a global variable inside a function, use global.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>data = (1, 2, 3)<br><br>def update():<br>&nbsp; &nbsp; global data<br>&nbsp; &nbsp; data = (4, 5, 6)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>However, excessive use of global is discouraged. Prefer passing data as arguments especially immutable structures like tuple in python.<\/p>\n\n\n\n<p><strong><em>Also read: <\/em><\/strong><a href=\"https:\/\/www.guvi.in\/blog\/how-to-practice-python\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>How to Practice Python Effectively: Small Projects You Can Build Right Away<\/em><\/strong><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The nonlocal Keyword<\/h2>\n\n\n\n<p>Used to modify variables in the enclosing scope.<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>def outer():<br>&nbsp; &nbsp; nums = (1, 2)<br><br>&nbsp; &nbsp; def inner():<br>&nbsp; &nbsp; &nbsp; &nbsp; nonlocal nums<br>&nbsp; &nbsp; &nbsp; &nbsp; nums = (3, 4)<br><br>&nbsp; &nbsp; inner()<br>&nbsp; &nbsp; print(nums)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>This is another clean tuple in python with example that shows how enclosing scope works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why Tuples Fit Perfectly with Scope and Namespace<\/h2>\n\n\n\n<ul>\n<li>Tuple in python is immutable, so its values cannot be changed once created<\/li>\n\n\n\n<li>Prevents accidental data modification across different scopes<\/li>\n\n\n\n<li>Ideal for storing constant or fixed values<\/li>\n\n\n\n<li>Makes scope-related code safer and more predictable<\/li>\n\n\n\n<li>Helps beginners clearly understand controlled access to variables<\/li>\n\n\n\n<li>Often used as tuple in python with example when explaining namespace and scope concepts<\/li>\n<\/ul>\n\n\n\n<p><em>Master Python the right way with HCL GUVI\u2019s <\/em><a href=\"https:\/\/www.guvi.in\/courses\/programming\/python\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=Understanding+Namespace+and+Scope+in+Python\" target=\"_blank\" rel=\"noreferrer noopener\"><em>Python Course<\/em><\/a><em>, where complex concepts like decorators are broken down through real-world examples and hands-on practice.&nbsp;<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping it up:<\/h2>\n\n\n\n<p>Namespaces may seem invisible, but they silently power every Python program you write. Once you understand how Python manages names, your code becomes clearer, safer, and more professional.<\/p>\n\n\n\n<p>Whether you are defining a simple variable, working with a tuple in python, or building large applications, namespaces ensure that everything stays in its rightful place.<\/p>\n\n\n\n<p>Keep practicing, experiment with examples, and soon namespaces will feel completely natural.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQs<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1770278958609\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>1. What is a namespace in Python?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Namespace is a container, which holds variable names and the objects that these variables represent, and prevents name conflicts in Python.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1770278967806\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>2. What is scope in Python?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Scope is a determining factor of where a variable can be accessed within a program. Although there may be a variable, it has to be in scope to be used.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1770278982613\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>3. What is the difference between namespace and scope?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Namespace refers to the location of a variable in terms of where it is stored whereas scope refers to where it can be accessed.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1770278996129\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>4. What is the LEGB rule in Python?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>LEGB rule determines how Python searches variables: Local, Enclosing, Global and Built-in.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1770279010702\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>5. Can the same variable name exist in different namespaces?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Yes, it is possible to have different namespaces of the same variable in Python, but this would not result in conflicts.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Imagine you have a notebook where you write down phone numbers. You might save your best friend as \u201cAlex,\u201d your colleague as \u201cAlex,\u201d and your cousin as \u201cAlex.\u201d Without additional context, calling the right Alex would be impossible. To avoid confusion, you probably organize them as Alex (Friend), Alex (Office), and Alex (Cousin). Python faces [&hellip;]<\/p>\n","protected":false},"author":63,"featured_media":105282,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[717],"tags":[],"views":"368","authorinfo":{"name":"Vishalini Devarajan","url":"https:\/\/www.guvi.in\/blog\/author\/vishalini\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/02\/Understanding-Namespace-and-Scope-in-Python-A-Complete-Beginners-Guide-300x116.png","jetpack_featured_media_url":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/02\/Understanding-Namespace-and-Scope-in-Python-A-Complete-Beginners-Guide.png","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/100310"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=100310"}],"version-history":[{"count":5,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/100310\/revisions"}],"predecessor-version":[{"id":105285,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/100310\/revisions\/105285"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/105282"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=100310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=100310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=100310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}