QUESTION 14 OF 15

What is the difference between an iterable and an iterator?

Reveal the answer and explore the explanation.

14
MediumHigh priority

What is the difference between an iterable and an iterator?

Answer
Answer

An iterator yields successive items through __next__ and raises StopIteration when exhausted.

Practical example

Iterate through a dataset without knowing its length beforehand.

Reference: Further reading ↗

Last 30 min revisionHigh-yield interview Q&As