Connection to Iterables

Introduction to For Loops

Connection to Iterables

🙋 Need help? Ask an expert now!

For Loops & Iterables

What is an iterable?

An iterable can come in many different forms, but there is one specific key to an iterable that is what makes it important for a for loop. This means that for any for loop, you must be using an interable as that is what you will be going through in the looop. A more official definition is below:

In Python, we say that a value is an iterable when your program can iterate over it. In short, an iterable is a value that represents a sequence of one more values.

Containers:

Containers are data structures holding elements, and that support membership tests. They are data structures that live in memory, and typically hold all their values in memory, too. In Python, some well known examples are:

All of these data structures are containers which is synonymous with an iterable

  • List
  • Set
  • Dictionary
  • Tuple
  • Strings

Containers are easy to grasp, because you can think of them as real life containers: a box, a cupboard, a house, a ship, etc.

Edit Me on GitHub!