列表推導(dǎo)式
輕量級的循環(huán)創(chuàng)建列表
a=[x for x in range(0,4)]
print(a)
b=[x for x in range(3,10)]
print(b)
c=[x for x in range(3,23,2)]
print(c)
d=[x for x in range(3,10) if x%2==0]
print(d)
e=[x for x in range(3,10) if x%2!=0]
print(e)
f=[(x,y) for x in range(1,3) for y in range(3)]
print(f)
# 實現(xiàn)[1,2,3,4.......100]變成[[1,2,3],[4,5,6]...]
a=[x for x in range(1,101)]
b=[a[x:x+3] for x in range(0,len(a),3)]
print(b)