What is a function parameter =[] for?
Antoon Pardon
antoon.pardon at rece.vub.ac.be
Tue Nov 24 11:41:08 EST 2015
Op 24-11-15 om 16:48 schreef Chris Angelico:
> On Wed, Nov 25, 2015 at 2:46 AM, Antoon Pardon
> <antoon.pardon at rece.vub.ac.be> wrote:
>> 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.
>
> () 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
So on what grounds would you argue that () is not a literal.
--
Antoon.
More information about the Python-list
mailing list