Python Day 03

2019-03-08  本文已影响0人  牧笛_ini

Generator

An infinite list cannot be enumerated because of the limits of ram. But we could use the generator to identify the principles of list generation.

Note: use the generator as the List Comprehensions but replace the [] by ()

l=[x*(x-1) for x in rang(100)]
g=(x*(x-1) for x in rang(100))

l is a list while the g is a generator

how to call a generator

上一篇 下一篇

猜你喜欢

热点阅读