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
Was this helpful?