# 自动生成 1 2 3 l=list(range(1,4)) print(l) #求 1*1 2*2 3*3 l2=[] for x in range(1,4): l2.append(x*x) print(l2) # 简化 print([x * x for x in range(1, 4)]) # 求 x*x中的偶数 print([x * x for x in range(1, 4) if x % 2 == 0]) # 求双层循环 print([m + n for m in 'ABC' for n in 'XYZ']) # 字典中打印key=value d = {'x': 'A', 'y': 'B', 'z': 'C' } for k, v in d.items(): print(k, '=', v)
标签:ABC,生成器,列表,range,l2,print From: https://www.cnblogs.com/haha1988/p/17537823.html