This question has already been answered:
- Using global in Python 3 responses
Please tell me how the reserved word "global" works in Python
This question has already been answered:
Please tell me how the reserved word "global" works in Python
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
When creating a new variable in a function, they act only in the limit of the function. To change global variables inside a function, define them with global. (An example is the answer above)
When new variables are created inside a function, they have a local scope. That is, such variables are defined only within the function body, and they are destroyed when the function returns control to the caller. To be able to change global variables inside a function, these variables should be defined in the function body using the global statement.
count = 0 ... def foo(): global count count += 1 # Изменяет значение глобальной переменной count Source: https://ru.stackoverflow.com/questions/957580/
All Articles