小编use*_*337的帖子

如何在已定义变量后更改变量?

我正在尝试添加或减去已定义的变量,但我无法弄清楚如何使用新值覆盖旧值.

a = 15

def test():
    a = a +10
    print ( a )

test()
Run Code Online (Sandbox Code Playgroud)

错误信息:

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    test()
  File "test.py", line 4, in test
    a = a +10
UnboundLocalError: local variable 'a' referenced before assignment
Run Code Online (Sandbox Code Playgroud)

python scope python-3.x

21
推荐指数
2
解决办法
7992
查看次数

标签 统计

python ×1

python-3.x ×1

scope ×1