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

Popular posts from this blog

Quotation marks to wrap an element in HTML

What is the difference between iostream and iostream.h in cpp?

The Basic Structure of a Full-Stack Web App