Generator

From CS 61A Wiki
Revision as of 20:37, 4 July 2014 by Axis (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Jump to: navigation, search

In Python, a generator is a concise way to create an iterator. A generator returns a generator object.

A generator is created by using the yield statement instead of a return statement in a function.

A generator is lazy, producing an item only when asked for it, so it is memory efficient.