Top Python Libraries

Top Python Libraries

Understanding Python Iterators and Generators in Depth(Python Core in Action 17)

Explore how Python’s `for in` statement works, dive deep into iterators, generators, and container types to optimize your code for better performance.

Meng Li's avatar
Meng Li
Aug 31, 2024
∙ Paid
Iterator in Python. Understanding Iterator in simple way. | by ...

Welcome to the "Python Core in Action" Series

Table of Contents

Table of Contents

Meng Li
·
July 12, 2024
Read full story

When you first started with Python, you might have written something like `for i in [2, 3, 5, 7, 11, 13]: print(i)`.

The `for in` statement in Python is straightforward and much simpler compared to the early `for (int i = 0; i < n; i++) printf("%d\n", a[i])` loops in C++ or Java.

But have you ever wondered what exactly happens in Python when a `for in` loop runs? What kinds of objects can be used with `for in`?

In this lesson, we'll dive into Python's container types and explore iterators and generators.

User's avatar

Continue reading this post for free, courtesy of Meng Li.

Or purchase a paid subscription.
© 2026 Meng Li · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture