python
[Python] Simple yield generator example
# Generator function
def generator(count):
i = 0
while i < count:
yield i
i += 1
def test_generator():
for value in generator(4):
print("\nGenerated value :", value)
pass
Output
Generated value : 0
Generated value : 1
Generated value : 2
Generated value : 3
Generated value : 1
Generated value : 2
Generated value : 3
Was this helpful?
Similar Posts
- Calculate simple and compound interest in Python
- [Python] Pytest fixture example with cleanup and teardown
- [Python] Inheritance and adding variable. Page object example
- Python Measure the execution time of small bits of Python code with the timeit module
- [Python] Use json.dumps() to pretty-print Python dicts
- [Python] The get() method on Python dicts and its "default" arg
- [Python] Different ways to test multiple flags at once in Python