结论:python和js是非常类似的,除了基本类型以外的类型都是引用传递
a = "abc"
def f1(b):
b= "asdf"
f1(a)
print(a) #值传递abc
a= [1,2,3]
def f1(b):
b[0] = 0
f1(a)
print(a) #引用传递[0,2,3] 同理还有map
a= [1,2,3]
f1(a[:])
print(a) #[1,2,3] 切片会复制一份内存出来 和go语言的最大差异
class A:
def __init__(self):
self.a = 1
a = A()
a.a = 2
def f1(b):
b.a = 3
f1(a)
print(a.a) #引用传递3