使用[] + for语句是解析列表
而使用() + for语句是产生生成器
实例代码如下:
alist = [1, 2, 3, 4, 5] another_list = [i for i in alist] print another_list a_generator = (i for i in alist) print a_generator for i in a_generator: print i
2022-07-25 20:43:07
使用[] + for语句是解析列表
而使用() + for语句是产生生成器
实例代码如下:
alist = [1, 2, 3, 4, 5] another_list = [i for i in alist] print another_list a_generator = (i for i in alist) print a_generator for i in a_generator: print i