Op 24-11-15 om 15:34 schreef Chris Angelico: > On Wed, Nov 25, 2015 at 1:24 AM, Antoon Pardon > <antoon.par...@rece.vub.ac.be> wrote: >>> Start thinking of it as a constructor call rather than a literal, and >>> you'll get past most of the confusion. >> >> That doesn't change the fact it does look like a literal and not like >> a constructor. > > Then explain how this is a literal: > > squares = [x*x for x in range(int(input("How far? ")))] > > Or even a simple example like this: > > coords = (randrange(10), randrange(10)) > > Neither of them is a literal, even though one of them isn't even > constructing a list. Tuples may be constant, but they still don't have > a literal form. (Constant folding can make them function the same way > literals do, though. If a tuple is constructed of nothing but > immutable constants - including an empty tuple - then CPython will > generally create a constant for the whole tuple and use that, rather > than manually constructing one every time. But the same is true of > other expressions involving nothing but constants.) > > So if it (in your opinion) looks like a literal but isn't one, whose > fault is it? Yours or the language's? Not a rhetorical question. > > ChrisA >
-- https://mail.python.org/mailman/listinfo/python-list