python-yield

yield

1. Action, suspends the function and then the item caller returns a value, then resumes where it left off

2. Usage

def add(a):
for i in a:

yield i + 2

a = [1,2,3,4]

f  = add(a)

for i in f:

print(i + '  ')

Output: 3,4,5,6

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324782896&siteId=291194637