Change the future

Friday 2:35 p.m.–3:05 p.m.

Loop like a native: while, for, iterators, generators

Ned Batchelder

Audience level:
Core Python (Language, Stdlib)


Python provides powerful primitives for iterating over your data in ways that let you express yourself clearly and directly. But even programmers familiar with the tools don't use them as fully as they could. This talk will cover Python's iteration tools, from basic loops to generators and how to add iteration to your own classes. Come learn how looping was meant to be!


This talk will cover Python's iteration tools from while loops to iterators to generators to itertools. Starting from first principles, I demonstrate Python's simple but powerful idea of iteration, and how it is used throughout the language and standard library. A central idea is that iteration is a key part of any program, and abstracting your particular iterations properly is a great way to improve the structure of your code.