What is the difference between an iterable and an iterator?
Reveal the answer and explore the explanation.
14MediumHigh priorityWhat is the difference between an iterable and an iterator?
Answer
MediumHigh priority
What is the difference between an iterable and an iterator?
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 ↗