Python function global variables?

前端 未结 6 818
广开言路
广开言路 2020-11-22 04:49

I know I should avoid using global variables in the first place due to confusion like this, but if I were to use them, is the following a valid way to go about using them? (

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 05:11

    You must use the global declaration when you wish to alter the value assigned to a global variable.

    You do not need it to read from a global variable. Note that calling a method on an object (even if it alters the data within that object) does not alter the value of the variable holding that object (absent reflective magic).

提交回复
热议问题