The Python Game Book

code games. learn Python.

User Tools

Site Tools


Sidebar

Github:

en:glossary:g:global_variables

global variables

Python has a global statement to make a variable global, see also scope of variables

not to be confused with:

  • globals() - shows all global variables of the current module

see also:

how to avoid global variables

To avoid the use of global reasons why not to use global you can either:

  • create a class variable (directly below the class definition, before the __init__ function. All class variables can be accessed and modified from outside the class as well as from inside the class.
  • create a module (like config.py) and import this module in all your modules. Put your variable declarations inside this module. You can access and change the values from other modules
en/glossary/g/global_variables.txt · Last modified: 2020/06/12 21:56 by horst