Pointers

Justin Sheehy dworkin at ccs.neu.edu
Thu Mar 23 18:03:03 EST 2000


Curtis Jensen <cjensen at be-research.ucsd.edu> writes:

> 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.  

Right.  A variable is a reference, which is similar in some ways to a
pointer.  However, variables are automatically dereferenced when they
are accessed.

In your example above, one can think of the second line not as making
b into a pointer to a, but rather to the place that a was pointing to
at the time of the assignment.

-Justin

 




More information about the Python-list mailing list