Pointers

Curtis Jensen cjensen at be-research.ucsd.edu
Thu Mar 23 23:49:48 CET 2000


Jason Stokes wrote:
> 
> Curtis Jensen wrote in message <38D00DCE.9740380F at be-research.ucsd.edu>...
> >I haven't found anything about pointers in python.  Is there a pointer
> >type?  If so, what is the syntax?
> 
> Since you ask this I assume you come from a C background.
> 
> All Python variables are references.  References are similar to C pointers
> (indeed, internally they are implemented the same way) except references
> don't support pointer arithmetic.
> 
> So you don't need to declare a variable of type "pointer to string" (or what
> have you) because all Python variables could be considered to have the type
> "reference to object."

I've done most of my programming in Fortran, but I have a good C
background too.  

Python does work on a reference setup, but it's not exactly like
pointers.  For example:
>>> a = 5
>>> b = a
>>> a = 3
>>> print b
5

If b were a pointer to b then print b would return 3, not 5.  There is
the problem of mutable types and immutable types here, but the same
thing occurs if you use a mutable type.  So, pointers and python
referances are not the same.  

-- 
Curtis Jensen
cjensen at be-research.ucsd.edu
http://www-bioeng.ucsd.edu/~cjensen/
FAX (425) 740-1451



More information about the Python-list mailing list