3
Loops and Iterators
Programs often need to process through sequential data—of fixed or dynamic length. As a primarily imperative programming language, Python makes it easy to implement sequential processing using loops. This is the general pattern: On each pass through a loop, read data—stored in variables, lists, dictionaries, and so on—and carry out corresponding state modifications or I/O operations. Loops in Python feel natural and capable for the most common tasks involving built-in data types, container types, and user-defined classes.
Python also supports iterators, which enable a more functional-style approach to processing arbitrary streams of data. Instead of directly interacting with how the sequential data is stored, you can use ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access