Generators MCQs | JoinMyTutor
MCQs on Python generators with yield keyword.
Generators MCQs
-
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.
-
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.
-
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.
-
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.
-
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
Senior Full-Stack InstructorPython & 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.