February 2006
Intermediate to advanced
648 pages
14h 53m
English
The built-in function id() returns the identity of an object as an integer. This integer usually corresponds to the object’s location in memory, although this is specific to the Python implementation and the platform being used. The is operator compares the identity of two objects. The built-in function type() returns the type of an object. For example:
# Compare two objects
def compare(a,b):
print 'The identity of a is ', id(a)
print 'The identity of b is ', id(b)
if a is b:
print 'a and b are the same object'
if a == b:
print 'a and b have the same value'
if type(a) is type(b):
print 'a and b have the same type'The type of an object is itself an object. This type object is uniquely defined and is always the same for ...