About 404,000 results
Open links in new tab
  1. Python - Global Variables - W3Schools

    Variables that are created outside of a function (as in all of the examples in the previous pages) are known as global variables. Global variables can be used by everyone, both inside of functions and outside. Create a variable outside of a function, and use it inside the function.

  2. python - How can I use a global variable in a function? - Stack Overflow

    Jul 11, 2016 · def use_global_variable(): return global_variable + '!!!' and now we can use the global variable: >>> use_global_variable() 'Foo!!!' Modification of the global variable from inside a function. To point the global variable at a different object, you are required to …

  3. Using and Creating Global Variables in Your Python Functions

    In this tutorial, you'll learn how to use global variables in Python functions using the global keyword or the built-in globals() function. You'll also learn a few strategies to avoid relying on global variables because they can lead to code that's difficult to understand, debug, and maintain.

  4. Global keyword in Python - GeeksforGeeks

    Feb 21, 2025 · The global keyword in Python allows a function to modify variables that are defined outside its scope, making them accessible globally. Without it, variables inside a function are treated as local by default.

  5. Python Global Variables

    In Python, a global variable is a variable defined outside of any function, making it accessible throughout the entire module or script. Unlike local variables that are confined to a specific function's scope, global variables can be read and modified from any part of the code.

  6. 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.

  7. Python Global Variables – How to Define a Global Variable

    May 12, 2022 · To begin with, you will learn how to declare variables in Python and what the term 'variable scope' actually means. Then, you will learn the differences between local and global variables and understand how to define global variables and how to use the global keyword. Here is what we will cover:

  8. Python Global Keyword (With Examples) - Programiz

    In Python, the global keyword allows us to modify the variable outside of the current scope. It is used to create a global variable and make changes to the variable in a local context. Before we learn about the global keyword, make sure you have got some basics of Python Variable Scope.

  9. Python Global Variables - PythonHello

    In Python, a global variable is a variable that is defined outside of any function or class and is available for use throughout the entire program. Global variables are defined using the global keyword, which specifies that a particular variable is a global variable rather than a local variable.

  10. Mastering Global Variables in Python: Concepts, Usage, and Best ...

    3 days ago · In Python programming, variables play a crucial role in storing and manipulating data. Global variables, in particular, have a unique scope that allows them to be accessed and modified from different parts of a program. Understanding how to define and use global variables correctly is essential for writing efficient and maintainable Python code. This blog post will delve into the fundamental ...

  11. Some results have been removed
Refresh