我正在尝试添加或减去已定义的变量,但我无法弄清楚如何使用新值覆盖旧值.
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)