working with pointers

Chris Cioffi evenprimes at gmail.com
Tue May 31 15:17:54 EDT 2005


Nope, numbers too. When you do:
 a = 4
 You are storing a reference to the literal 4 in a. 
 >>> a = 4
>>> dir(a)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', 
'__delattr__', '__
div__', '__divmod__', '__doc__', '__float__', '__floordiv__', 
'__getattribute__', '__getne
wargs__', '__hash__', '__hex__', '__init__', '__int__', '__invert__', 
'__long__', '__lshif
t__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', 
'__or__', '__p
os__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', 
'__reduce__', '__redu
ce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', 
'__rmul__', '__ror__', '
__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', 
'__rxor__', '__setattr
__', '__str__', '__sub__', '__truediv__', '__xor__']
>>>
 Unlike a list, there is no way to alter the interger value of 4.
 If we go further, and then do something like:
>>> b = a
>>> b
4
>>>
 Both a and b refer to the same object, in this case the 4 object.
 If you want a copy of the object check out the copy module.
 Chris
 On 31/05/05, Michael <slick_mick_00 at hotmail.com> wrote: 
> 
> except numbers??
> 
> "Dave Brueck" <dave at pythonapocrypha.com> wrote in message
> news:mailman.299.1117566077.18027.python-list at python.org...
> > Michael wrote:
> > > sorry, I'm used to working in c++ :-p
> > >
> > > if i do
> > > a=2
> > > b=a
> > > b=0
> > > then a is still 2!?
> > >
> > > so when do = mean a reference to the same object
> >
> > Always.
> >
> > > and when does it mean make a copy of the object??
> >
> > Never.
> >
> > -Dave
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 



-- 
"I was born not knowing and have had only a little time to change that here 
and there." -- Richard Feynman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050531/f724a314/attachment.html>


More information about the Python-list mailing list