About 156,000 results
Open links in new tab
  1. How can I use a global variable in a function? - Stack Overflow

    Jul 11, 2016 · How do I create or use a global variable inside a function? How do I use a global variable that was defined in one function inside other functions? Failing to use the global …

  2. How to declare a global variable in Python correctly

    Jan 28, 2023 · If a function assigns to a variable name (which your greet() function does for the player variable), then that variable name is treated as local everywhere in the function, even if …

  3. python - Using global variables between files? - Stack Overflow

    See Python's document on sharing global variables across modules: The canonical way to share information across modules within a single program is to create a special module (often called …

  4. Why does assigning to my global variables not work in Python?

    If you don't assign to a in the function (as with printA ()) then Python uses the global variable A. To mark a variable as global you need to use the global keyword in Python, in the scope that …

  5. How to create module-wide variables in Python? [duplicate]

    Dec 30, 2009 · EDIT: If, for some reason, you need to do something like this in a very old version of Python that doesn't have the global keyword, there is an easy workaround. Instead of …

  6. How can I access global variable inside class in Python

    May 30, 2012 · How can I access global variable inside class in Python Asked 13 years, 5 months ago Modified 12 months ago Viewed 285k times

  7. Correct Use Of Global Variables In Python 3 - Stack Overflow

    Feb 20, 2012 · Which is the correct use of global variables in Python 3?: 1) Stating global VAR_NAME once in the core script (not within a function) and then simply referring to the …

  8. python - How can I change a global variable from within a …

    The a in your first line is a global variable (so called because it exists in the global scope, outside of any function definitions). The a in the other lines is a local variable, meaning that it only …

  9. How do you declare a global constant in Python?

    Jun 10, 2014 · My program contains multiple files and classes, and I would like to be able to access this variable from anywhere, and if possible define it as constant. How do you define a …

  10. python - Why do I get a "referenced before assignment" error …

    See Python reference. You should declare variable without global and then inside the function when you want to access global variable you declare it global yourvar.