Generator expressions are a cross between comprehensions and generator functions. They use a similar syntax as comprehensions, but they result in the creation of a generator object which produces the specified sequence lazily. The syntax for generator expressions is very similar to list comprehensions:
( expr(item) for item in iterable )
It is delimited by parentheses instead of the brackets used for list comprehensions.
Generator expressions are useful for situations where you want the lazy evaluation of generators with the declarative concision of comprehensions. For example, this generator expression yields a list of the first one-million square numbers:
>>> million_squares = (x*x for x in range(1, 1000001))
At this point, none of the squares have been created; we've just captured the specification of the sequence into a generator object...