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
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