我想做这样的事情,但我得到一个 SyntaxWarning 并且它没有按预期工作
RAWR = "hi"
def test(bool):
if bool:
RAWR = "hello" # make RAWR a new variable, don't reference global in this function
else:
global RAWR
RAWR = "rawr" # reference global variable in this function
print RAWR # if bool, use local, else use global (and modify global)
我怎样才能让它工作?传入 True 或 False 会修改全局变量。