Is 'everything' a refrence or isn't it?

Donn Cave donn at drizzle.com
Fri Jan 13 23:22:53 EST 2006


Quoth Steven D'Aprano <steve at REMOVETHIScyber.com.au>:
| On Thu, 12 Jan 2006 16:11:53 -0800, rurpy wrote:
|> It would help if you or someone would answer these
|> five questions (with something more than "yes" or "no" :-)
|> 
|> 1. Do all objects have values?
...
|> 2. What is the value of object()?

[ I assume you mean, the object returned by object(). ]

It doesn't really have a value.  I can't think of any kind of
computation that could use this object directly.

|> 3. If two objects are equal with "==", does that
|>   mean their values are the same?

Yes.

| >>> 3.0 == 3
| True

Evidently the value of 3.0 is the same as the value of 3.

|> 4. Are object attributes part of an object's type
|>   or it's value, or something else?  (I think the first.)
|
| The type/class defines what attributes (generic) objects have. The value
| of the attribute lives with the instance itself (that's why fred.attribute
| and barney.attribute can be different).

I think to be strictly accurate, attributes and their values may reside
in a class instance, or in (one of) its class(es.)  In the most common
case, functions will be in the class and data will be in the instance,
but every variation on this is reasonably common.

| ... Whether you want to say the
| attribute itself is part of the class or part of the instance value is, in
| my opinion, not a useful question. The answer depends on which way you
| want to look at it.

For a given class and instance, it can be more obvious.  Take the object
returned by object(), which has attributes like '__reduce__' - all those
attributes may reasonably be considered "type" and not "value".

On the other hand, there are no constraints on how you may use these
namespaces.  You can use an instance, or a class, like you would use
a dictionary object, and then it's all value.

	Donn Cave, donn at drizzle.com



More information about the Python-list mailing list