Generators MCQs | JoinMyTutor

MCQs on Python generators with yield keyword.

Generators MCQs test learners’ knowledge of Python generators and lazy evaluation. Topics include yield statements, generator expressions, memory efficiency, pipelines, and using generators with iterators. Learners practice applying generators in data streaming, large dataset processing, and performance-critical code. These MCQs ensure students understand how to write efficient programs that handle massive data without exhausting memory.}

Generators MCQs

  1. What is a generator in Python?
    • A. A function using yield
    • B. A built-in iterator class
    • C. A list comprehension
    • D. A type of dictionary

    Answer: A — Generators are functions that use yield to produce values lazily.

  2. Which keyword is used to create a generator?
    • A. return
    • B. yield
    • C. generate
    • D. continue

    Answer: B — The yield keyword is used to produce generator values.

  3. Which function checks if an object is a generator?
    • A. isinstance(obj, generator)
    • B. inspect.isgenerator(obj)
    • C. type(obj) == generator
    • D. callable(obj)

    Answer: B — inspect.isgenerator() checks generator type.

  4. What happens when a generator function is called?
    • A. Runs immediately
    • B. Returns a generator object
    • C. Raises error
    • D. Executes yield

    Answer: B — Calling a generator returns a generator object but does not run code yet.

  5. What exception stops a generator?
    • A. StopIteration
    • B. EndError
    • C. StopGenerator
    • D. RuntimeError

    Answer: A — When a generator is exhausted, StopIteration is raised.

💡 Tips & Common Mistakes

Remember to review concepts carefully. Fill in custom tips for generators here.

📅 Last Updated: November 20, 2026

Vinod Kumar avatar

Vinod Kumar

Senior Full-Stack Instructor

Python & JavaScript Tutor at JoinMyTutor

Vinod teaches practical Python and JavaScript—ranging from basics to advanced web apps—with a focus on clear mental models, code readability, and interview preparation. He authors both the Python and JavaScript tracks on JoinMyTutor.

#Python #Flask #Pandas #JavaScript #Node.js #React #ES6+ #Async/Await #DOM Manipulation
banner