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

    Jul 11, 2016 · In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a new value anywhere within the function’s body, it’s assumed to be a …

  2. How to declare a global variable in Python correctly

    Jan 28, 2023 · How to declare global variables in a correct way in Python? What I'm doing wrong? I expected the code of tic-tac-toe working correctly but it didn't. To resolve the issue I tried to …

  3. 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 …

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

    May 30, 2012 · Now, if the declaration global g_c occurs anywhere within the method, even after any referencing or assignment, then Python defaults to finding the name g_c within global …

  5. global variable inside main function python - Stack Overflow

    May 12, 2013 · Actually, you can create a global variable inside a function using global. It's just a bad idea, because the variable won't exist until assigned to for the first time. The problem …

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

    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 …

  7. python - Viewing all defined variables - Stack Overflow

    Mar 11, 2009 · I'm currently working on a computation in python shell. What I want to have is Matlab style listout where you can see all the variables that have been defined up to a point …

  8. Python function global variables? - Stack Overflow

    150 Within a Python scope, any assignment to a variable not already declared within that scope creates a new local variable unless that variable is declared earlier in the function as referring …

  9. Python - Easiest way to define multiple global variables

    Dec 6, 2016 · The reason for this is that python treats classes as modules, so this works out well for setting up a list of global variables- such as when trying to make an interface with multiple …

  10. Global Variable from a different file Python - Stack Overflow

    5 while I do the test following the idea of @robertspierre to put all global variables in a glv.py file and then import it in other files where it is used, the demo codes is given bellow, hope it helps: …