python的函数传递

1
2
3
4
5
a = 1
def fun(a):
a = 2
fun(a)
print(a) #1
1
2
3
4
5
a = []
def fun(a):
a.append(1)
fun(a)
print(a) #[1]

在python中,strings, tuples, 和numbers是不可更改的对象,而 list, dict, set 等则是可以修改的对象