Generator Function
The generator function uses the 'yield' keyword.
mylist = [1,2,3,4,5,6,7,8,9,10]
def eo():
for item in mylist:
if item % 2 == 0:
yield f"{item} is even"
else:
yield f"{item} is odd"
for i in eo():
print(i)
Comments
Post a Comment
Write something to CodeWithAbdur!