On Fri, Feb 19, 2016 at 8:14 AM, Christian Gollwitzer <aurio...@gmx.de> wrote: > Am 16.02.16 um 03:02 schrieb Rick Johnson: >> >> On Friday, February 12, 2016 at 1:51:35 AM UTC-6, John Ladasky wrote: >>> >>> I like lazy evaluation. >> >> >> Well, it is a "Pythonic feature" no doubt. > > > > ?? I'm confused. Does Python have lazy evaluation? I thought that Python > does eager evaluation. At least this snippet seems to confirm: > > def arg(): > print("Evaluating arg") > return None > > def func(x): > print("Evluating func") > print(x) > > func(arg()) > > If I run it, the output is: > > Evaluating arg > Evluating func > > and I think that with side effects, only eager evaluation is really > predictable.
Python's form of lazy evaluation comes in the form of functions that return iterables, rather than concrete lists: >>> def square(x): ... print("Squaring %d..." % x) ... return x*x ... >>> squares = map(square, range(10)) >>> next(squares) Squaring 0... 0 >>> next(squares) Squaring 1... 1 >>> next(squares) Squaring 2... 4 ChrisA -- https://mail.python.org/mailman/listinfo/python-list