These lessons are part of a Real Python video course by Christopher Trudeau.
Efficient Iterations With Python Iterators and Iterables (Overview)
00:00
Welcome to Efficient Iterations With Python Iterators and Iterables. My name is Christopher and I’ll be your guide. In this course, you’ll learn about iterables, the iter()
, and next()
built-in functions, iterators and the iterator protocol, generators, and the yield
keyword, generator expressions, and the sequence protocol.
00:26 The code in this course was tested using Python 3.12, but any supported version of Python from 3.7 up will work.
00:34
Sometimes it can be fun to drill down on something that you’ve taken for granted. For example, have you ever considered just how a for
loop actually works?
00:42
What kinds of things can you iterate over? What kinds of things can go after the in
keyword and how does the loop get the next item during the actual iteration?
00:53
Sure, there are loads of built-in things you can iterate on, but can you write your own? Well, the answer to that last one is yes. Iteration in Python is based on the iterator protocol, which is a loose definition of class methods that get used by the for
loop and other code that iterates.
01:11 This course covers just what it means to be an iterable, how iterators are related to iterables, and how you can write your own code that implements the iterator protocol.
01:22 Next up, I’ll dive into what it means to be an iterable.
You must own this product to join the conversation.