Get up to 80 % extra points for free! More info:

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 will gain knowledge worth hundreds of thousands for a few crowns

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

Buy all currently available lessons with exercise submitting and other features for just $0.90
Current account balance $0
By buying this package, you'll have access to all 2 articles (2 lessons) in this course.

This article is licensed: Premium, by buying this article, you agree with the terms of use.

What will you get from us in the next lessons?
  • 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.

Article has been written for you by Shift
Avatar
As an author I'm interested mainly in industry automation. I'm also writing music and literature. In my spare time I'm working on a few games in Game Maker Studio.
Activities