waitTime=0.5
def is_ava():
waitTime = waitTime + 0.1
print waitTime
if __name__ == '__main__':
is_ava()
为什么UnboundLocalError: local variable 'waitTime' referenced before assignment
,我已经宣布了waitTime。
Python版本:2.7
答案 0 :(得分:4)
要修改全局变量,您需要declare it inside the function as a global variable:
waitTime=0.5
def is_ava():
global waitTime # <--------
waitTime = waitTime + 0.1
print waitTime
if __name__ == '__main__':
is_ava()