What is a function parameter =[] for?

BartC bc at freeuk.com
Tue Nov 24 09:43:43 EST 2015


On 24/11/2015 14:18, Ned Batchelder wrote:
> 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?

> 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

And [] is [] gives False too!

For my own benefit, I use the term Handle when shared values are involved.

It comes from the use of file handles (what you get in some languages 
when you open or create a file) which everyone can understand:

* If you copy handle F to G like in an assignment, it obviously doesn't 
copy the contents of the file, just the handle.

* If I compare the contents of files F and H, they might be the same, 
but they are not necessarily the same file.

* If F and G are the same handle, then if I update a file via F, I will 
see the same change via handle G.

The main difference is that when F and G go out of scope and the handles 
disappear, the file hopefully still exists! (And ideally the file is 
first closed via one of the handles.)

 From your example, the syntax '[]' is roughly equivalent to 
'create_empty_file()' in my analogy.

(I don't really want to get back to default arguments, but that would 
extend to:

   def fn(a = create_empty_file()):

which makes it easier to appreciate the implications of 'early' and 
'late' binding. But I still think that reads as though you get a fresh, 
empty file each time.)

-- 
Bartc

-- 
bartc






More information about the Python-list mailing list