Python-Generator
Generator
yield():
in ordinary function
Coroutine(协同程序):
可以运行的独立函数的调用,函数可以暂停或者挂起,并在需要的时候可以从离开的地方继续或重新开始。
(与函数生成的局部变量到了函数外失效不同)
1 |
|
We can use the generator to realize the Fibonacci sequence.
1 |
|
List Comprehension:
Generate a list that can be divided by 2 and not 3.
1 |
|
Dictionary Comprehension:
Generate a dictionary that numbers in 0-9 can be distinguished as even or not.
1 |
|
Set Comprehension:
1 |
|
String Comprehension: Non-existent.
In string, in “…”, the Python is all string.
Tuple Comprehension:
1 |
|
We can find that it is not tuple comprehension, it is a generator comprehension!
1 |
|
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!