What is a function parameter =[] for?

Ned Batchelder ned at nedbatchelder.com
Tue Nov 24 09:18:19 EST 2015


On Tuesday, November 24, 2015 at 7:57:54 AM UTC-5, Marko Rauhamaa wrote:
> Antoon Pardon <antoon.pardon at rece.vub.ac.be>:
> 
> > You then switching to talking about objects, just gives the impression
> > that object is a synonym for value.
> 
> It isn't?

We are tangled up in another terminology conflict.  The word "value" is
being used in two different senses. It's understandable that this results
in confusion.  Neither use is incorrect, we just have to understand that
there are multiple meanings, and clarify where the meaning is uncertain.

1) In English, "value" means something like, what is this equal to? There
isn't another good word to use in place of "value" here. We might awkwardly
use the word "equivalence" as a synonym.  I'll use the word "evalue" (short
for "equal value" or "equivalence value" or "English value"). The ==
operator is useful for testing whether two values are "the same evalue".
In this sense, the expression "[]" always evaluates to the same value,
an empty list:

    >>> a = []
    >>> b = []
    >>> a == b
    True

2) In Python, "value" means, what object does a name refer to, or what
object did an evaluation produce.  We could use "referent" as a
synonym for this meaning.  The Python operator "is" tests whether two
values are the same referent, or, the same object. In this sense, "[]" 
always evaluates to a different value, because you get a new empty list
each time:

    >>> a = []
    >>> b = []
    >>> a is b
    False

Mutable objects are complicated because the same referent (object) can
change its evalue over time.

The confusion over mutable default arguments arises because the
defaulted argument always gets the same referent, but it might not
always be the same evalue.

--Ned.



More information about the Python-list mailing list