Objects, values and types

Objects are Python’s abstraction for data. All data in a Python program is represented by objects or by relations between objects. (In a sense, and in conformance to Von Neumann’s model of a stored program computer, code is also represented by objects.)

Every object has an identity, a type and a value. An object’s identity never changes once it has been created; you may think of it as the object’s address in memory. The is operator compares the identity of two objects; the id function returns an integer representing its identity (currently implemented as its address). An object’s type is also unchangeable.

(However, since Python 2.2, a gradual merging of types and classes has been started that makes this and a few other assertions made in this manual not 100% accurate and complete: for example, it is now possible in some cases to change an object’s type, under certain controlled conditions. Until this manual undergoes extensive revision, it must now be taken as authoritative only regarding classic classes, that are still the default, for compatibility purposes, in Python 2.2 and 2.3. For more information, see http://www.python.org/doc/newstyle.html).

An object’s type determines the operations that the object supports (e.g., does it have a length?) and also defines the possible values for objects of that type. The type function returns an object’s type (which is an object itself). The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable. (The value of an