According to answer to this question, yield break
in C# is equivalent to return
in Python. In the normal case, return
indeed stops a gener
The funny part is that both functions have the same bytecode. Probably there's a flag that sets to generator
when bytecode compiler finds the yield
keyword.
>>> def f():
... return
>>> def g():
... if False: yield
#in Python2 you can use 0 instead of False to achieve the same result
>>> from dis import dis
>>> dis(f)
2 0 LOAD_CONST 0 (None)
3 RETURN_VALUE
>>> dis(g)
2 0 LOAD_CONST 0 (None)
3 RETURN_VALUE