-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator_functions.py
More file actions
52 lines (43 loc) · 913 Bytes
/
Copy pathgenerator_functions.py
File metadata and controls
52 lines (43 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Learn about generator functions:
- Describe iterables series with code functions
- Are lazy evaluated: the next value in the sequence is computed on demand
- Can model infinite series/sequences: data streams, mathematical series with no end
- Can use pipelines
use the yield keyword
"""
def gen123():
# ...
yield 1
# ...
yield 2
# ...
yield 3
def gen246():
print("About to yield 2")
yield 2
print("About to yield 4")
yield 4
print("About to yield 6")
yield 6
print("About to return")
def main():
"""
Test function
:return:
"""
g = gen123()
print(g, type(g))
# yield next value
print(next(g))
# Iterate over the generator function
for v in gen123():
print(v)
h = gen246()
print(next(h))
print(next(h))
print(next(h))
print(next(h))
if __name__ == '__main__':
main()
exit(0)