a为生成器,b为列表
1 #_*_coding:utf-8_*_ 2 #__author__ = "csy" 3 4 a = (i for i in range(10000000)) 5 b = [i for i in range(10000000)] 6 7 print(b[1000]) 8 print(a[1000])
输出:
1000
File "C:/Users/...../PycharmProjects/1/4.py", line 7, in <module>
print(a[1000])
TypeError: 'generator' object is not subscriptable
b能直接打印第1000个元素,a不行。a要在真正循环调用时才生产。