How do you declare a global constant in Python?

You can just declare a variable on the module level and use it in the module as a global variable. An you can also import it to other modules.

#mymodule.py
GLOBAL_VAR = 'Magic String' #or matrix...

def myfunc():
    print(GLOBAL_VAR)

Or in other modules:

from mymodule import GLOBAL_VAR

Leave a Comment