Search⌘ K
AI Features

Yielding From...Return!

Discover how to use return statements with values inside Python 3.3+ generators. Learn why 'yield from' behaves this way and how to properly catch StopIteration exceptions to retrieve values from generators, enhancing your understanding of advanced Python features.

We'll cover the following...

Can we yield from return???

1.

What do you think the output of the following code will be?

⚠️ The following code is meant for > Python 3.3 versions.

Python 3.5
def some_func(x):
if x == 3:
return ["ftw"]
else:
yield from range(x)
print(list(some_func(3)))

2.

Where did the "ftw" go in the above code? Did it disappear due to some ...