QamoosTech
Programming FundamentalsIteration and generatorsIntermediatePython

Iterable

PronunciationIT-er-uh-bul

Definition

An iterable is anything you can loop over, one item at a time, such as a list, a string, a dictionary or a file.

Where you hear it

In Python tutorials about for loops, and when a function says it accepts any iterable.

Examples

  • The function accepts any iterable, so you can pass a list or a generator.
  • A string is iterable: the loop gives you one character at a time.
  • The sum function accepts any iterable, so it works on a set or a tuple too.

Common mistake

Thinking an iterable is the same as an iterator. An iterable can produce an iterator; the iterator is what keeps track of where you are.

Don't confuse with

An iterator, which hands out the items one by one and can be used only once.

Say it at work

  • In a meeting or chatType it as an iterable so callers aren't forced to pass a list.
  • In an email or ticketAny iterable works with this loop.