This module contains the type objects
for all the different Python types. For any two
objects of the same type or class, applying the
type() function to them
returns the same object:
>>> import types >>> type(2.5) <type 'float'> >>> type(2.5) is types.FloatType 1
Here are most of the members of the
types module. (A few more
obscure types exist; see the
Python Library Reference
if you are working with the
more exotic features of the language.)
BuiltinFunctionType | Built-in function such as
dir(). |
BuiltinMethodType | Built-in method such as the
.append() method on a list
object. |
ClassType | User-defined class. |
ComplexType | Complex number. |
DictType | Dictionary. |
FileType | File object. |
FloatType | Floating point number. |
FunctionType | User-defined function. |
GeneratorType | Generator (see generators above). |
InstanceType | Instance of a user-defined class. |
IntType | Integer. |
ListType | List. |
LongType | Long integer. |
MethodType | Method of a user-defined class. |
NoneType | The unique object
None. |
StringType | String. |
TupleType | Tuple. |
TypeType | Type object. |
UnicodeType | Unicode string. |
XRangeType | Result returned by
xrange(). |
In Python 2.2 and
beyond, the name of the type's constructor
function is the type object. This works for
int,
long,
float,
str (strings),
unicode,
tuple,
list, and
dict (dictionaries). For
example:
>>> type(2.5) is float 1