|
|
|
|
|
by TrianguloY
1057 days ago
|
|
A yield will simply return a generator object, which contains information about the next value to use, and how to continue the function execution. That's why you need to use functions that yield things inside loops or list(...). If you run it from different threads I guess it will be the same as calling the function multiple times, it will return a new started-from-the-top generator. def sum():
yield 1
yield 2
print(repr(sum()))
print(next(sum()))
print(next(sum()))
Prints <generator object sum at 0x7fc6f14823c0>
1
1
|
|