How can I assign a value of a variable only with the start of the game

I need that certain value of a variable be available in other functions.

Furthermore I want it initialised when loading the game, at which point the variables are set to their default value. Within functions, the value of the variables may be changed, but the value, which was initially assigned to the variable, is not affected by the new value which the function may assign the variable.

I want the initial value to be constant and for it to be impossible to update the value.

I'm grateful for your help, I'm a beginner in Python.

• Your question in its original form is somewhat confusing. I have attempted to clarify what you are asking. If I am incorrect in my assumptions, and edit, then please do not hesitate to roll back the edit. Dec 4, 2016 at 1:04

If I understand your question correctly, then I think you mean that you want a global constant that is initialised at the start of the game. The value of this global constant should be accessible in other functions, but those functions should not be able to change the value of that constant. Is that correct?

If I am correct in my assumption above, then the answer is in this question on StackOverflow: 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():
global GLOBAL_VAR
#do something


Or in other modules:

from mymodule import GLOBAL_VAR

• ok thank you this solved my question. Feb 1, 2020 at 14:30
• If this solved your problem, then please mark this question as the accepted answer, and upvote. Thanks. Jul 31, 2020 at 20:12