Skip to content

What makes Python interesting

Python is different but not too different and that makes it interesting and worthwhile for study. An example is Loop better: A deeper look at iteration in Python by Trey Hunner — “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.” A pre-requisite is some familiarity with “iterators” and “generators” and “dictionaries” as these are fundamental concepts utilized by Python looping constructs. They are reviewed in the article.

Unlike traditional C-style for loops, Python’s for loops don’t have index variables. There’s no index initializing, bounds checking, or index incrementing. Python’s for loops do all the work of looping over our numbers list for us.

So while we do have for loops in Python, we do not have have traditional C-style for loops. The thing that we call a for loop works very differently.

Hunner has a nice comparison and contrast to illustrate his point. The reason for all of this is noted:

There are lots of iterators built into Python, in the standard library, and in third-party Python libraries. These iterators all act like lazy iterables by delaying work until the moment you ask them for their next item.

This has implications in handling large sets of calculated things. Instead of carrying around a huge array or other data object, the one you need is obtained only when you need it for the amount of time you need to do something with it. That is a conceptual step up from basic programming paradigms.