Python入门:局部变量与全局变量2
例子1:
names=("Lili","Rain","Jack")
change_name(name):
names[0]="LiLy"
print(names)
结果:names=("LiLy","Rain","Jack") #列表可以在函数中直接修改
例子2:
names={"name":"LiLy","age":18,"sex":"F"}
change_name(name):
names[school]="Oldboy"
print(names)
结果:names={"name":"LiLy","age":18,"sex":"F","school":"Oldboy"} #字典可以在函数中直接修改