- Generator is a function which is responsible to generate a sequence of values. We can write generator functions just like ordinary functions, but it uses yield keyword to return values.
Example
Python
def mygen():
yield 'A'
yield 'B'
yield 'C'
g=mygen()
print(type(g))
print(next(g))
print(next(g))
print(next(g))
Output
PowerShell
<class 'generator'>
A
B
C
Ungraded Questions
Get ready for an exhilarating evaluation of your understanding! Brace yourself as we dive into the upcoming assessment. Your active participation is key, so make sure to attend and demonstrate your knowledge. Let’s embark on this exciting learning journey together!