pointers & references in python?

Aahz aahz at pythoncraft.com
Fri Aug 16 10:04:31 EDT 2002

In article <20020819223945.6e2edbfb.sami.sieranoja at pp.inet.fi>,
sami sieranoja  <sami.sieranoja at pp.inet.fi> wrote:
>is there something like this in python:
>a = 1
>b = &a
>b = 3
>print a

Yes and no.  Watch this:

>>> a = []
>>> b = a
>>> b.append(1)
>>> a

As you can see, simple assignment in Python *does* use something like
references; in fact, Python *only* uses references, and you cannot
access objects directly.  Thing is, some objects are immutable (e.g.
numbers and strings) and you cannot modify them.  This means that you
can't actually do operation you wish in precisely that way, you have to
put the immutable object in some kind of mutable container (list, dict,
class/class instance, or module).
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/

More information about the Python-list mailing list