updated contents from Atlas repo
This commit is contained in:
42
iterables/simplest_generators.doctest
Normal file
42
iterables/simplest_generators.doctest
Normal file
@@ -0,0 +1,42 @@
|
||||
>>> def gen_123():
|
||||
... yield 1
|
||||
... yield 2
|
||||
... yield 3
|
||||
...
|
||||
>>> gen_123 # doctest: +ELLIPSIS
|
||||
<function gen_123 at 0x...>
|
||||
>>> gen_123() # doctest: +ELLIPSIS
|
||||
<generator object gen_123 at 0x...>
|
||||
>>> for i in gen_123():
|
||||
... print(i)
|
||||
1
|
||||
2
|
||||
3
|
||||
>>> g = gen_123()
|
||||
>>> next(g)
|
||||
1
|
||||
>>> next(g)
|
||||
2
|
||||
>>> next(g)
|
||||
3
|
||||
>>> next(g)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
StopIteration
|
||||
|
||||
|
||||
>>> def gen_AB():
|
||||
... print('start')
|
||||
... yield 'A'
|
||||
... print('continue')
|
||||
... yield 'B'
|
||||
... print('end.')
|
||||
...
|
||||
>>> for c in gen_AB():
|
||||
... print('--->', c)
|
||||
...
|
||||
start
|
||||
---> A
|
||||
continue
|
||||
---> B
|
||||
end.
|
||||
Reference in New Issue
Block a user