python 生成器需注意的小问题

liaixiaobai 2 0 PDF 2020-12-17 08:12:57

在Python中,生成器和函数很像,都是在运行的过程中才会去确定各种变量的值,所以在很多情况下,会导致各种各样的问题。 def generator_test1(): # 0...9 generator x = (i for i in range(10)) # 5..9 generator x_filter = filter(lambda y: y >= 5, x) # first use the x L = list(x) print("L, x", L) # then use x_filter l = list(x_filter) print("l, x_filter"

用户评论
请输入评论内容
评分:
暂无评论