Is behavior of += intentional for int?
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. :)
> class A(object):
> 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
> 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
Derek D. Martin
GPG Key ID: 0x81CFE75D
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 196 bytes
Desc: not available
More information about the Python-list