python学习之路(1)
2016-01-13 16:07
483 查看
列表解析表达式:
List comprehensions derive from set notation; they are a way to build a new list by
running an expression on each item in a sequence, one at a time, from left to right。
List
comprehensions are coded in square brackets (to tip you off to the fact that they make
a list) and are composed of an expression and a looping construct that share a variable
name (row, here).
If the last section’s for loop looks like the list comprehension expression introduced
earlier, it should: both are really general iteration tools. In fact, both will work on any
object that follows the iteration protocol—a pervasive idea in Python that essentially
means a physically stored sequence in memory, or an object that generates one item at
a time in the context of an iteration operation. An object falls into the latter category
if it responds to the iter built-in with an object that advances in response to next. The
generator comprehension expression we saw earlier is such an object.
List comprehensions derive from set notation; they are a way to build a new list by
running an expression on each item in a sequence, one at a time, from left to right。
List
comprehensions are coded in square brackets (to tip you off to the fact that they make
a list) and are composed of an expression and a looping construct that share a variable
name (row, here).
If the last section’s for loop looks like the list comprehension expression introduced
earlier, it should: both are really general iteration tools. In fact, both will work on any
object that follows the iteration protocol—a pervasive idea in Python that essentially
means a physically stored sequence in memory, or an object that generates one item at
a time in the context of an iteration operation. An object falls into the latter category
if it responds to the iter built-in with an object that advances in response to next. The
generator comprehension expression we saw earlier is such an object.
相关文章推荐
- python子进程模块subprocess详解与应用实例 之一
- Python 正则表达试
- python的输入输出
- 用ladon框架封装Python为Webservice接口以及调用接口的方法
- Python 2.5.10 sorted
- Python字符串原理剖析------万恶的+号
- 【LeetCode】【Python题解】Single Number & Maximum Depth of Binary Tree
- 关于Numpy,Scipy,Scikit-learn的查询文档
- python二维数组
- selenium-webdriver(python) (十) 如何处理下拉框
- python socket编程详细介绍
- python数据类型转换
- Python编程的例子----股票数据接口
- python 的内嵌time模板翻译及说明[转]
- 笨办法学Python学习笔记 练习21
- Python数据类型学习笔记
- Python 2.5.9 filter
- Python的sys.stdout、sys.stdin重定向
- 如何制作python安装模块(setup.py)
- python getopt使用