del z # z与它所绑定的值解绑,即值10的引用计数减为2 # 注意 del不是不是删除z的意思本质是接触变量名的绑定,内存回收的目的
import sys sys.getrefcount(a) # 查看引用计数
deff(): import sys a = 10 print(sys.getrefcount(a)) b = a print(sys.getrefcount(a)) c = [a] print(sys.getrefcount(a)) del b print(sys.getrefcount(a)) del c print(sys.getrefcount(a))
from itertools import chian a= [1,2,3,4,5] b = [4,5,65,56] c = {'a':1,'b':4} for i in chain(a,b): print(i) # 1, 2 ,3 ,4,5,4,5,65,56 for i in chain(a,c.values()): print(i) # 1,2,3,4,5,1,4
去除嵌套
1 2 3 4 5 6 7
from itertools import chain a = [[1,2,3],[4,5,6],[7,8,9]] for i in chain(a): print(i) # 1,2,3,4,5,6,7,8,9 # 取值 b = list(chian(*a)) # [1,2,3,4,5,6,7,8,9]