将列表生成式中[]改成() 之后数据结构是否改变?
答案:是,从列表变为生成器
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>
答案:是,从列表变为生成器
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>