迭代器 什么叫迭代 可以被for循环的就说明他们是可迭代的,比如:字符串,列表,字典,元祖,们都可以for循环获取里面的数据 下面我们看一个代码: number = 12345 for i in number: print(i) 输出: Traceback (most recent call last): File "D:**.py", line 272, in <module> for i in number: TypeError: 'int' object is not…
十三. Python基础(13)--生成器进阶 1 ● send()方法 generator.send(value) Resumes the execution, and "sends" a argument which becomes the result of the current yield expression in the generator function. The send() method, like __next__(), returns the next v…
一,生成器表达式 #生成器表达式比列表解析更省内存,因为惰性运算 #!/usr/bin/env python #_*_coding:utf-8_*_ new_2 = (i*i for i in range(100)) #生成器表达式 print(list(new_2)) #注意括号是小括号 对比 #!/usr/bin/env python #_*_coding:utf-8_*_ # egg_list=['鸡蛋%s' %i for i in range(10)] 列表推倒式 # print(egg…