我是python中的新手,我在使用global指令方面遇到了很多麻烦.
这是一个代码示例:
mouse = "a"
background = "b"
list_ab = [mouse, background]
def func ():
for item in list_ab:
global item # I want to modify the GLOBAL item, which is mouse
# and background.
item = "modified"
print mouse # must be "modified" not "a"
print background # must be "modified" not "b"
Run Code Online (Sandbox Code Playgroud)
这就是问题.我该如何解决?