列表推导式
2020-04-22 本文已影响0人
Carver_
列表推导式
所谓的列表推导式,就是指的轻量级循环创建列表
1. 基本的方式

输出结果:
[0, 1, 2, 3] [1, 2, 3, 4, 5, 6] [1, 3, 5]
2. 在循环的过程中使用if

输出结果:
[2, 4, 6] [1, 3, 5] [1, 3, 5]
3. 2个for循环

输出结果:
[(1, 3), (1, 4), (2, 3), (2, 4), (3, 3), (3, 4)]