'Is there a better solution for manipulating one value across multiple functions other than global variables? [closed]

I’m creating a text based adventure game in Python and for the the state of character and amount of one item I’m using global variables, but I’ve heard it’s not the best solution and I can’t seem to find one solid answer.



Solution 1:[1]

You have heard correctly. Global variables should always be avoided.

For the purposes of your project, I recommend you look into Object Orientated Programming (OOP) in Python. This is a better way of keeping track of the state of objects in your program.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Saief El Gebali