It is very usefull when you know your function will return a huge set of values that you will only need to read once
Code:
def myFun(n): for i in range(0,n): yield i it=myFun(5) for i in it: print i
Output:
0 1 2 3 4
def myFun(n): for i in range(0,n): yield i it=myFun(5) for i in it: print i
0 1 2 3 4
0 comments:
Post a Comment