1.拆包
def func(): return 1,2,3,4 result = func() print(result) n1,n2,n3,n4 = func() #拆包
print(n1)
print(n2)
print(n3)
print(n4)
2.浅拷贝
import copy li = [1,1,2,3,4,5,6,7,8,9, ["s","a","b","c"] ] l3 = copy.copy(li) #浅拷贝 #print(l3[-1]) l3[-1].append("d") l3.append("11111") print(li) print(l3) print(id(li)) print(id(l3))
3.深拷贝
import copy li = [1,1,2,3,4,5,6,7,8,9, ["s","a","b","c"] ] l3 = copy.deepcopy(li) #深拷贝 #print(l3[-1]) l3[-1].append("d") l3.append("11111") print(li) print(l3) print(id(li)) print(id(l3))
4.循环删除list
import copy li = [1,1,2,3,4,5,6,7,8,9] l3 = copy.deepcopy(li) for i in l3: 循环删除list时,会导致下标错乱,所以不能直接循环需要删除的list,可以循环值相同的其他list来解决 if i%2!=0: li.remove(i) print(li)