Is behavior of += intentional for int?

Derek Martin code at pizzashack.org
Sun Aug 30 20:21:09 CEST 2009


On Sun, Aug 30, 2009 at 05:43:42PM +0000, OKB (not okblacke) wrote:
> Derek Martin wrote:
> 
> > If Python is to say that objects have values,
> > then the object can not *be* the value that it has, because that is a
> > paradoxical self-reference.  It's an object, not a value.
> 
>     	But does it say that objects have values?  I don't see where you 
> get this idea.  

Yes, it does say that.  Read the docs. :)

http://docs.python.org/reference/datamodel.html

(paragraph 2)


> class A(object):
>     	pass

> a = A()
>
>     	What is the "value" of the object now bound to the name "a"

In Python, the value of objects depends on the context in which it is
evaluated.  But when you do that, you're not getting a value that is
equivalent to object, but of some property of the object.  The object
has no intrinsic value until it is evaluated.  In that sense, and as
used by the python docs, I would say that the value of the object a is
"true" -- you can use it in boolean expressions, and it will evaluate
as such.  

>       I would say that in Python, objects do not have values.
> Objects are values.

You can say that, but if you do you're using some definition of
"value" that's only applicable in Python and programming languages
which behave the same way.  It would be more correct to say that an
object is a collection of arbitrary data, which has a type and an
identity, and that the data in that collection has a value that
evaluates in context.  An object is an abstract collection of data,
and abstractions have no value.  You can not measure them in any
meaningful way.  The data contained in the collection does, however,
have a value.  When you reference an object in an expression, what you
get is not the value of the object, but the value of some peice of
data about, or contained in, that object.

It is this property of objects, that the value evaluated depends on
the context, that I think demonstrates that an object is *not* a
value.  Values never change, as we've said in this thread: 3 is always
3.  'a' is always 'a'.  But an object x can evaluate to many different
values, depending on how it is used.  The definition of the object
would need to allow for it to do so, but Python allows that, and even
encourages it.

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20090830/88beb233/attachment.pgp>


More information about the Python-list mailing list