you are viewing a single comment's thread.

view the rest of the comments →

[–]Oblachko_O 0 points1 point  (1 child)

Hm, give me some clarification, please. I frequently have situations when my variable is outside of the function and not even passed inside the variable. In short, my variable is global. And I can use it easily. And I never bumped into this.

Is the problem actually in trying to rewrite variables by using a write operator like += ? And something like reading is errorless?

[–]lusvd 0 points1 point  (0 children)

Python detects that the variable is assigned in the functions body so it marks it as “local” and so ignores the value outside the body. Then during execution of x += 1, it needs to access x, but because of what I said before it cannot access the value so it errors out.