看一段代码
其中第5行是一个generator expression,第7行是一个list expression.
-
[root@cdn ~]# python
-
Python 2.6.6 (r266:84292, Jan 21 2013, 17:47:21)
-
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
-
Type "help", "copyright", "credits" or "license" for more information.
-
>>> (x*2 for x in range(5))
-
<generator object <genexpr> at 0x2b06b7b144b0>
-
>>> [x*2 for x in range(5)]
-
[0, 2, 4, 6, 8]
-
>>>
阅读(835) | 评论(0) | 转发(0) |