About 405,000 results
Open links in new tab
  1. Python Scope - W3Schools

    Local Scope. A variable created inside a function belongs to the local scope of that function, and can only be used inside that function.

  2. Python Variable Scope (With Examples) - Programiz

    In Python, we can declare variables in three different scopes: local scope, global, and nonlocal scope. A variable scope specifies the region where we can access a variable. For example, def add_numbers(): sum = 5 + 4. Here, the sum variable is created inside the function, so it can only be accessed within it (local scope). This type of ...

  3. Global and Local Variables in Python - GeeksforGeeks

    Jul 25, 2024 · Python Global variables are those which are not defined inside any function and have a global scope whereas Python local variables are those which are defined inside a function and their scope is limited to that function only.

  4. Python Scope of Variables - GeeksforGeeks

    Mar 23, 2023 · In Python, function variables have local scope and cannot be accessed directly from outside. However, their values can still be retrieved indirectly. For example, if a function defines var = 42, it remains inaccessible externally unless retrieved indirectly.

  5. Python Variable Scope – Local, Global, Built-in, Enclosed

    Dec 9, 2020 · Learn Python Variable Scope-types of Variable scope: local scope, global scope, enclosed scope, built-in scope; Global keyword in python etc

  6. Python Variable Scope with Local & Non-local Examples

    May 11, 2020 · Learn about Python variable scopes and the 'LEGB' rule. Follow our step-by-step tutorial and see how global and nonlocal keywords are used today!

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

    Local scope: The names that you define in this scope are only available or visible to the code within the scope. Scope came about because early programming languages (like BASIC) only had global names.

  8. Python Scope Rules: Local and Global Variables (With Examples)

    Local Scope. In Python, a local scope is created whenever a function is called. A local scope is a temporary workspace where variables and objects created within a function exist. These variables can only be accessed within the function and are destroyed when …

  9. A Comprehensive Guide to Variable Scope in Python

    Jun 21, 2023 · In this comprehensive guide, we've discussed the four variable scope levels in Python (built-in, global, enclosing, and local) and explored how to modify variables from different scopes using the global and nonlocal keywords.

  10. Python Variable Scope: A Comprehensive Guide - CodeRivers

    Jan 30, 2025 · Understanding variable scope is crucial for writing clean, error - free, and efficient Python programs. It helps you manage the lifecycle of variables, avoid naming conflicts, and ensure that your code behaves as expected.

  11. Some results have been removed
Refresh