Unable to modify a global int, but can modify a list. How?

前端 未结 2 1358
醉酒成梦
醉酒成梦 2021-01-13 19:22

LISTL = [] VAR1 = 0 def foo(): ... VAR1 += 1 ... return VAR1 ...

2条回答
  •  借酒劲吻你
    2021-01-13 20:02

    If you assign to a variable within a function, that variable is assumed to be local unless you declare it global.

提交回复
热议问题