如果有多个for循环,则最终的数据数量为多个for循环的笛卡尔积.
# 多个for循环的列表推导式
# range取值5-15 ,步长为5,range()取值顾头不顾尾,所以取值为5和10
list_e = [(e, f*f) for e in range(3) for f in range(5, 15, 5)]
print(list_e)
lis = [f for f in range(5, 15, 5)] # 取值5-15 ,步长为5,range()取值顾头不顾尾,所以取值为5和10
print(lis)
结果是:
[(0, 25), (0, 100), (1, 25), (1, 100), (2, 25), (2, 100)]
[5, 10]