Bird
Raised Fist0

Which of these objects is NOT an iterator in Python?

easy🧠 Conceptual Q2 of Q15
Python - Magic Methods and Operator Overloading
Which of these objects is NOT an iterator in Python?
AA file object
BA list
CA generator
DAn object with __iter__ and __next__ methods
Step-by-Step Solution
Solution:
  1. Step 1: Recall iterator definition

    An iterator must have __iter__ and __next__ methods.
  2. Step 2: Check each option

    A list is iterable but not an iterator itself. Generators, file objects, and objects with both methods are iterators.
  3. Final Answer:

    A list -> Option B
  4. Quick Check:

    List is iterable, not iterator [OK]
Quick Trick: Iterable ≠ iterator; list is iterable only [OK]
Common Mistakes:
MISTAKES
  • Thinking lists are iterators
  • Confusing iterable and iterator
  • Assuming all objects with __iter__ are iterators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes