insert
操作导致外部参数值的改变,如下所示。def change_a(a):
a_tmp = a
a_tmp.append(1)
print("函数中a的值为:", a)
print("函数中a_tmp的值为:", a_tmp)
a = [2,3,4]
change_a(a)
print("外部a的值为:", a)
import copy
def change_copy_a(a):
a_tmp = copy.deepcopy(a)
a_tmp.append(1)
print("函数中a的值为:", a)
print("函数中a_tmp的值为:", a_tmp)
a = [2,3,4]
change_copy_a(a)
print("外部a的值为:", a)
如果有问题或者写的有错误,欢迎一起来交流~