Skip to content Skip to sidebar Skip to footer

Return Value In Generator Function Python 2

I'm wondering how I can write a generator function that also has the option to return a value. In Python 2, you get the following error message if a generator function tries to ret

Solution 1:

Mandatory reading: Understanding Generators in Python

Key information:

yield anywhere in a function makes it a generator.

Function is marked as generator when code is parsed. Therefore, it's impossible to toggle function behavior (generator / not generator) based on argument passed in runtime.

Post a Comment for "Return Value In Generator Function Python 2"