标签:限制 none 机制 /usr 完整 UNC lis pre code
生成器
创建一个generator, 有很多种方法
1 >>> L = [x*x for x in range(10)] 2 >>> L 3 4 >>> g = (x*x for x in range(10)) 5 >>> g
1 #!/usr/bin/python 2 # -*- coding: utf-8 -*- 3 4 a = [] 5 for i in range(10): 6 a.append(i*2) 7 8 print(a) 9 10 11 print("========== 上述代码等效于下面这句 ========== ") 12 b = [i*2 for i in range(10)] 13 print(b) 14 15 16 print("============== 更进阶写法 ============== ") 17 c = [func(i) for i in range(10)] 18 print(c)
标签:限制 none 机制 /usr 完整 UNC lis pre code
原文地址:https://www.cnblogs.com/cheese320/p/8968983.html