

Passing an iterable to the iter function will always give us back an iterator, no matter what type of iterable we're working with. We can ask each of these iterables for an iterator using Python's built-in iter function. This dictionary has two key-value pairs: > counts = We asked the same question twice and Python gave us two different answers. But if we ask the same question again, Python will tell us that 9 is not in squares. If we ask whether 9 is in our squares generator, Python will tell us that 9 is in squares. Let's take the same list of numbers and the same generator object: > numbers = If we then take the same generator object and pass it to the sum function, we might expect that we'd get the sum of these numbers, which would be 88. We can pass our generator object to the tuple constructor to make a tuple out of it: > tuple(squares) Let's say we have a list of numbers and a generator that will give us the squares of those numbers: > numbers = We're going to start off our journey by taking a look at some "gotchas." After we've learned how looping works in Python, we'll take another look at these gotchas and explain what's going on. In this article we'll dive into Python's for loops to take a look at how they work under the hood and why they work the way they do.

Python's for loops don't work the way for loops do in other languages.
