What really happens when the yield and returns are used in such a way in the dragon in this way?
def find_all (a_str, sub): start = 0 while correct: start = a_str.find (sub, start) if start == -1: begin to yield returns start = len (sub ) # Use start + 1 for finding overlapping matches 1
Is it still a generator?
Yes, it is still a generator return
(approx.) < Code> stop arrester is equal to lifting.
It has made it stand out:
Specification: Return
A generator function can also have return statement of the form:
Note that an expression_list is not allowed to return statement in the body of a generator (However, of course, they are nested non-generator within the generator. Can appear in the body of functions).When a return statement comes, the function returns, finally executing the appropriate positions (if any exist). Then a stop-setting exception is raised, the signal is that the itater has ended. A stop inturnation exception is also raised, if the control flows at the end of the generator without any explosion withdrawal.
Note that returns means "I am doing, and nothing is going back", generator functions and non-generator work for both.
Note that Return is not always the same as extending Stopiteration: The difference is that how efforts have been made to stop / except for example,
Gt; & Gt; & Gt; Def f1 (): ... Try: ... Return ... except ...: produce ... 1> gt; & Gt; & Gt; Print list (F1 ()) []
Because, as any function, just returns back, but
& gt; & Gt; & Gt; DF F2 (): ... Try: ... to increase the Stop Iteration ... except its ... ... yield 42 & gt; & Gt; & Gt; Print list (F2 ()) [42]
Because stop separation is taken as "no exception" as any exception.
Comments
Post a Comment