Practice mode Python

What turns an ordinary Python function into a generator function?

Correct answer B. Using the yield keyword in its body

Explanation

Any function whose body contains yield is a generator function. Calling it returns a generator object, and each yield pauses execution and hands a value back, resuming from that point on the next request. Python has no @generator decorator, and returning a list builds all values at once.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.