What is a function parameter =[] for?

Chris Angelico rosuav at gmail.com
Tue Nov 24 10:17:14 EST 2015


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?

ChrisA



More information about the Python-list mailing list