why cannot assign to function call

sturlamolden sturlamolden at yahoo.no
Wed Jan 7 12:45:00 CET 2009

On Jan 7, 2:02 am, Steven D'Aprano
<ste... at REMOVE.THIS.cybersource.com.au> wrote:

> In Python code, there are no references and no dereferencing.

The why does CPython keep track of reference counts?

> You can't, because Python doesn't have references. In a language with
> references, that's easy.

Python does not 'pass-by-reference' as Fortran or Pascal do.

> It's harder (impossible?) to write a version that will operate on
> arbitrary types, but that's statically typed languages for you.

In Python an assignment (re)binds the name to another value. You can
certainly write a swap method for mutable types. But you cannot use
the assignment operator to swap the values.

> No no no, lists and tuples store *objects*.

>>> a = 123456789
>>> b = [a]
>>> c = [a]
>>> d = [a, a]

>>> b[0] is a
>>> c[0] is a
>>> d[0] is a
>>> d[1] is a

Where is the object 'a' stored?

More information about the Python-list mailing list