第一种,只是在list中添加一个数组对象:
def changeme( mylist ):
"修改传入的列表"
mylist.append([1,2,3,4])
print ("函数内取值: ", mylist, id(mylist))
return
mylist = [10,20,30]
changeme( mylist )
print ("函数外取值: ", mylist, id(mylist))
打印结果
函数内取值: [10, 20, 30, [1, 2, 3, 4]] 140224644586944
函数外取值: [10, 20, 30, [1, 2, 3, 4]] 140224644586944
完全改变了数组
def changeme( mylist ):
"修改传入的列表"
mylist = [1,2,3,4]
print ("函数内取值: ", mylist, id(mylist))
return
mylist = [10,20,30]
changeme( mylist )
print ("函数外取值: ", mylist, id(mylist))
打印结果
函数内取值: [1, 2, 3, 4] 139681458488064
函数外取值: [10, 20, 30] 139681459379648