将列表生成式中[]改成() 之后数据结构是否改变?

答案:是,从列表变为生成器

L = [x*x for x in range(10)]
print(L) #[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

g = (x*x for x in range(10)) 
print(g) #<generator object <genexpr> at 0x02FA6F90>

 

posted @ 2019-07-15 16:44  anobscureretreat  阅读(175)  评论(0编辑  收藏  举报