references ???

Steve Holden sholden at holdenweb.com
Fri Nov 2 09:00:20 EST 2001


"Thomas Weidner" <wolf359_ at gmx.net> wrote ...
> In <9rtpsc$13j2 at newton.cc.rl.ac.uk>, Richard Brodie wrote:
>
>
> > "Thomas Weidner" <wolf359_ at gmx.net> wrote in message
> > news:pan.2001.11.01.17.30.27.280.2271 at gmx.net...
> >
> >
> >> I think anybody here knows what references,like in java,c++ or perl,
> >> are. How can i use references in python ?
> >
> > Implicitly. Consider the following:
> >
> >>>> a = [1,2,3]
> >>>> b = a
> >>>> b[1] = 20
> >>>> print a
> > [1, 20, 3]
>
> Interesting....
> Is this also possible for single values like ints ?
> How do i make clear if i want a copy of a or a reference to it ?

Generally, this only matters if the object is mutable (i.e. can change in
place). This is the case for lists, for which you would use either
copy.copy() or copy.deepcopy(), depending on how deeply you want to do the
copying.

Simple assignment always binds the name on the left-hand side to the object
referenced on the right-hand side.

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list