What is a function parameter =[] for?

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


On Tue, Nov 24, 2015 at 9:41 AM, Antoon Pardon
<antoon.pardon at rece.vub.ac.be> wrote:
> Op 24-11-15 om 16:48 schreef Chris Angelico:
>> () is not a literal either.
>
> The byte code sure suggests it is.
>
> Take the following code:
>
> import dis
>
> def f():
>   i = 42
>   t = ()
>   l = []
>
> dis.dis(f)
>
> That produces the following:
>
>
>   4           0 LOAD_CONST               1 (42)
>               3 STORE_FAST               0 (i)
>
>   5           6 LOAD_CONST               2 (())
>               9 STORE_FAST               1 (t)
>
>   6          12 BUILD_LIST               0
>              15 STORE_FAST               2 (l)
>              18 LOAD_CONST               0 (None)
>              21 RETURN_VALUE

I'm not sure what this is meant to prove. None is clearly an
identifier, not a literal, and it also gets treated as a constant in
the code above.

> So on what grounds would you argue that () is not a literal.

This enumerates exactly what literals are in Python:

https://docs.python.org/3/reference/lexical_analysis.html#literals

I think it's a rather pedantic point, though. How are nuances of the
grammar at all related to user expectations?



More information about the Python-list mailing list