Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

What is a generator in Python?

  1. A A function that returns a list
  2. B A function containing yield that produces values lazily, one at a time
  3. C A class that creates objects
  4. D A random number producer
Answer

A function containing yield that produces values lazily, one at a time

Generators hold one value in memory at a time rather than the whole sequence, which is why they are used for large files and streams.

All Python MCQs

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as