Reference Variables In Python Like Those In PHP

Luke Plant L.Plant.98 at cantab.net
Tue Aug 15 15:23:21 EDT 2006


Chaos wrote:
> Is It possible to have reference variables like in PHP
...
> Is this available in python?

You should note that, to a nearest equivalent, all variables are
reference variables in Python.  The difference is in what assignment
does -   += in Python does an assignment of a new object for immutable
objects.  For mutable objects like lists, += does an in place
modification.

x = 1
y = x  #  y and x now point to the same object
y += 1 # not any more, because ints are immutable,
           # and += is defined not to mutate for ints

Luke




More information about the Python-list mailing list