User Tools

Site Tools


cs_lang:python:things-to-know:lazy-vs-eager

This is an old revision of the document!


Lazy vs Eager evaluation

Python generally uses a eager evaluation (in contrary to Haskell).

>>> r = range(10)
>>> print(r)
range(0, 10)
>>> print(r[3])
3

This was not the case with Python 2 (without iterators):

>>> r = range(10)
>>> print r
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> print r[3]
3

Lazy evaluation saves execution time for large ranges.

cs_lang/python/things-to-know/lazy-vs-eager.1358949289.txt.gz · Last modified: 2013/01/23 14:54 by cedric