5 ms·
Except you can use `return` without argument to return early from a generator, and `yield` without argument yields None, so they need to be separate keywords.
by eurleif 14y ago
Except you can use `return` without argument to return early from a generator, and `yield` without argument yields None, so they need to be separate keywords.
- gejjaxxita 14y agoThis functionality is so arcane that it's not needed.
- eurleif 14y agoEarly return is definitely needed. I guess you could make bare `return` early return, and `return None` the way to yield None, but that's kind of confusing.
- gejjaxxita 14y agoI agree that would be confusing, but I question that early return is needed - I don't think I've ever seen a generator example where early return is used. It could be that it's because I haven't seen enough examples of course. Please share some examples of a generator with early return which can't be accomplished easily and clearly in some other way.