Pointers

D-Man dsh8290 at osfmail.rit.edu
Mon Mar 20 14:35:48 CET 2000


Would I be correct if I said that Python always uses pointers and never
makes a copy of an object unless explicitly requested using copy()?

Grant Edwards wrote:
> 
> On Wed, 15 Mar 2000 14:25:18 -0800, Curtis Jensen <cjensen at be-research.ucsd.edu> wrote:
> 
> >I haven't found anything about pointers in python.  Is there a pointer
> >type?
> 
> Yes.
> 
> >If so, what is the syntax?
> 
> x = 3
> 
> # x is now a pointer to an integer object whose value is 3.
> 
> y = "asdf"
> 
> # y is now a pointer to a string object whose value is "asdf".
> 
> x = y
> 
> # x now points to the same object as does y.
> 
> z = (0,4,5)
> 
> # z points to a tuple containing integer objects 0 4 and 5
> 
> a = [x,y,z]
> 
> # a is a pointer to a list containing the objects pointed to by x
> # y and z
> 
> b = a[1]
> 
> # b is a pointer to the same object pointed to by y.
> 
> # and so on....
> 
> All variables are pointers to objects.
> 
> The tricky thing is that some objects can be changed, and some
> can not.
> 
> --
> Grant Edwards                   grante             Yow!  I was in a HOT
>                                   at               TUB! I was NORMAL! I was
>                                visi.com            ITALIAN!! I enjoyed th'
>                                                    EARTHQUAKE!
> --
> http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list