Lesson 2 - Iterators, Generators and Some Functions in Python
In the last lesson, Python Collections - Tuples and Lists, we learned in depth about working with tuples and lists.
In this lesson, we'll introduce some of the more advanced techniques of functional programming in Python. Let's look at lambda functions, iterators and generators, and a few built-in functions.
Iterators and Generators
Iterators
Iterators are objects that have the special __next__
method and return a single value each time. Iterators are a subset of
iterable objects that have the special __iter__
method. We used
iterable objects, for example, in the for
loop. But let's go back
to the iterators. We create an iterator using the iter()
function
from an iterable object, such as a list.
Example:
...End of the preview...
Continue further
You've come here and that's great! We believe that the first lessons showed you something new and useful
Do you want to continue the course? Go to the premium section.
Buy this course
This article is licensed: Premium, by buying this article, you agree with the terms of use.
- Unlimited and permanent access to individual lessons.
- High quality IT knowledge.
- Skills to help you get your dream and well-paid job.
Article description
Requested article covers this content:
In this tutorial we'll take a look at iterators and generators. We'll also deepen our knowledge of comprehensions and learn a few built-in functions.
You gain credits by supporting our network. This is done by sending a helpful amount of money to support the site, or by creating content for the network.