列表推导
[x * x for x in range(10) if x % 3 == 0]
[0, 9, 36, 81]
注意:没有元组的推导
g = (i**2 for i in range(2, 10))
type(g)
<class 'generator'>next(g)
4list(g)
[9, 16, 25, 36, 49, 64, 81]
个人理解元组内类型才是生成器,也就是<class 'generator'>
[x * x for x in range(10) if x % 3 == 0]
[0, 9, 36, 81]
g = (i**2 for i in range(2, 10))
type(g)
<class 'generator'>next(g)
4list(g)
[9, 16, 25, 36, 49, 64, 81]
个人理解元组内类型才是生成器,也就是<class 'generator'>