#全局变量 school = ‘lianhedaxue‘ def test(name): #强制修改全局变量 global school school = ‘haha‘ print (‘before change‘,name,school) name = ‘Jack‘ #这个函数就是这个变量的作用域 print (‘after change‘,name) name = ‘Tom‘ test(name) print (name) print (school)
时间: 2025-01-06 02:55:23