Object Identity and Type
Useful functions for finding out information about objects
- type(obj) - Returns the type of an object (which itself is a special object)
a = [1,2,3]
t = type(a) # t = ListType
- id(obj) - Returns the identity of an object (an integer)
i = id(a)
- isinstance(obj,type) - Tests the type of an object
import types
if isinstance(a,types.ListType):
print "a is a list"
else:
print "a is not a list"
|