What is a function parameter =[] for?

Ian Kelly ian.g.kelly at gmail.com
Tue Nov 24 14:15:02 EST 2015


On Tue, Nov 24, 2015 at 11:45 AM, Antoon Pardon
<antoon.pardon at rece.vub.ac.be> wrote:
> I think limiting literals to lexical tokens is too limited. Sure we
> can define them like that in the context of the python grammar, but
> I don't see why we should limit ourselves to such a definition outside
> that context.
>
> I see nothing wrong with regarding -42 as a literal while according
> to the python grammar it isn't.
>
> There is nothing wrong with the notion that a literal can be a
> compounded value.

I'm somewhat inclined to agree with this. Taking an example from
another language, if you use Javascript you'll hear all the time about
"object literals" or "object literal notation". If you read the
ECMAScript spec, however, you won't find the phrase "object literal"
in there once. It seems that the common usage of "literal" is not the
same as the way it's used in formal writing of language
specifications.

> But no matter what you want to call it. The dis module shows that
> -42 is treated in exactly the same way as 42, which is treated
> exactly the same way as () or as (5, 8, 13) which is treated
> differently from [] or [5, 8, 13].

This is an implementation detail. The compiler would also be free to
compile -42 into byte code as the negation of the constant 42. That 42
is a literal, on the other hand, is part of the language
specification.



More information about the Python-list mailing list