Python‎ > ‎keywords‎ > ‎

yield


Definition
Yield equal to return but execute only iterable values.

Syntax
yield

Parameters
N/A

Examples
Yield return the list value in takewhile method.
from itertools import *
def takewhile1(x):
    yield x<15


list=[1,3,5,7,9]
for i in takewhile(takewhile1, list ):
    print (i)

>>> 
1
3
5
7
9
>>>

Comments