What is a function parameter =[] for?

Antoon Pardon antoon.pardon at rece.vub.ac.be
Tue Nov 24 10:46:22 EST 2015


Op 24-11-15 om 16:17 schreef Chris Angelico:
> On Wed, Nov 25, 2015 at 2:03 AM, Antoon Pardon
> <antoon.pardon at rece.vub.ac.be> wrote:
>> Op 24-11-15 om 15:34 schreef Chris Angelico:
>>> On Wed, Nov 25, 2015 at 1:24 AM, Antoon Pardon
>>> <antoon.pardon at 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? ")))]
>>
>> So are you saying
>>
>>   () isn't a literal
>>
>> because
>>
>>   (x * x for x in range(int(input("How far? ")))) isn't a literal?
> 
> I'm pretty sure tuple/list/dict display predates comprehensions, and
> was already not a literal syntax. Steven, you know the history better
> than I do - confirm or deny?

What is your point? I say that [] looks like a literal. Because it
sure resembles () which is a literal.

That [] in fact isn't a literal doesn't contradict it looks like
one.

That you can come up with more complicated list expressions that
are more easily recognizable as not being literals is beside the
point because we have generator expressions that look similar to
those list comprehensions and those generator expressions don't
contradict that () is a literal.

-- 
Antoon.




More information about the Python-list mailing list