一个普通的例子
def func(x):
print('this is x:', x)
x = 2
print('this is new x:', x)
x = 50
func(x)
print('this is also x:', x)
>>>this is x: 50
>>>this is new x: 2
>>>this is also x: 50第二个例子
def func(): global x print('this is x:', x) x = 2 print('this is new x:', x)
x = 50func()print('this is also x:' ,x)
>>>this is x: 50>>>this is new x: 2>>>this is also x: 2
1万+

被折叠的 条评论
为什么被折叠?



