pyDay13

内容来自雪峰的官方网站。

1、把listdictstrIterable变成Iterator可以使用iter()函数

>>> L = iter([1, 2, 3, 4, 5, 7])
>>> L
<list_iterator object at 0x000002014FB66160>
>>> next(L)
1
>>> next(L)
2
>>> next(L)
3
>>> next(L)
4
>>> next(L)
5
>>> next(L)
7
>>> next(L)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration

 

2、Iterator的计算是惰性的,只有在需要返回下一个数据时它才会计算。

Iterator甚至可以表示一个无限大的数据流,例如全体自然数。而使用list是永远不可能存储全体自然数的。

 

3、函数式编程就是一种抽象程度很高的编程范式,纯粹的函数式编程语言编写的函数没有变量。

 

4、把函数作为参数传入,这样的函数称为高阶函数,函数式编程就是指这种高度抽象的编程范式。

>>> def add(a, b, f):
...     return f(a) + f(b)
...
>>> add(-3, -4, abs)
7

 

5、高阶函数是把函数看成对象,可以传入,还可以返回一个动态创建的函数。

 

posted @ 2017-02-26 16:53  xkfx  阅读(201)  评论(0编辑  收藏  举报