(In regards to Python 3.2)
I’m trying to make a statement along the lines of:
In Python, an object is…
According to the doc (http://docs.python.org/py3k/reference/datamodel.html#objects-values-and-types):
Every object has an identity, a type and a value
But where do attributes fall into that? If I do something like a = 3; print(a.__class__) I get <class 'int'> I assume that is the type of the object a references, meaning that "type" is an "attribute" of an object. So in that sense we can say a sufficient set of "things" an object has would be its identity, value and attributes. However, looking through the attributes of a using dir(a), I do not see anything resembling identity (even though I know the id() function will tell me that information).
So my question is are any of the following minimal statements to sufficiently describe the notion of a Python object?
In Python an object has attributes, of which always include an identity, type and value.
In Python an object has an identity and attributes, of which always include its type and value.
In Python an object has an identity, value and attributes, of which always include its type, among other things.
If not, could someone give me a definition that conveys the relationships attributes, identity, type and value for an object?
(I would prefer number 1 to be true. :P)
While you can access the type of an object through an attribute, its type isn’t just an attribute — the type defines how the object was created before it had any attributes at all. By that fact alone none of those statements is sufficient to describe a Python object.
I’d say it this way:
You should then give some examples of things people might not expect to be objects, like functions.
A paragraph on "What is an object" can be found in Dive Into Python: