About 509,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 keyword where …

  2. python - How to make a local variable (inside a function) global ...

    I'm using functions so that my program won't be a mess but I don't know how to make a local variable into global.

  3. 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 there is a …

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

    Dec 30, 2009 · Here is what is going on. First, the only global variables Python really has are module-scoped variables. You cannot make a variable that is truly global; all you can do is make a variable in …

  5. How to set a global variable in Python - Stack Overflow

    I'm trying to make a slot machine in Python, and I want to make a coins system, where you can actually earn coins so the game is better, but when I ran the code, it told me 'UnboundLocalError: local …

  6. 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 global constant in …

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

    25 You can think of Python global variables as "module" variables - and as such they are much more useful than the traditional "global variables" from C. A global variable is actually defined in a module's …

  8. Crear variables globales en Python - Stack Overflow en español

    Jul 19, 2019 · Yo soy bastante nuevo con la sintaxis de Python en particular como crear global, nonlocal y local variables y como declararlas sin errores de sintaxis. Por ejemplo en el programo siguiente, …

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

    May 30, 2012 · I understand using a global variable is sometimes the most convenient thing to do, especially in cases where usage of class makes the easiest thing so much harder (e.g., …

  10. Python syntax for creating and changing global variables

    Dec 17, 2022 · Very basic Python question but I want to make sure I'm using the global keyword properly after a couple of false starts. Creating a variable that needs to be global inside a function: …