1 \section{Built-in module
\sectcode{types
}}
4 \renewcommand{\indexsubitem}{(in module types)
}
6 This module defines names for all object types that are used by the
7 standard Python interpreter (but not for the types defined by various
8 extension modules). It is safe to use ``
\code{from types import *
}'' ---
9 the module does not export any other names besides the ones listed
10 here. New names exported by future versions of this module will
11 all end in
\code{Type
}.
13 Typical use is for functions that do different things depending on
14 their argument types, like the following:
18 def delete(list, item):
19 if type(item) is IntType:
25 The module defines the following names:
27 \begin{datadesc
}{NoneType
}
28 The type of
\code{None
}.
31 \begin{datadesc
}{TypeType
}
32 The type of type objects (such as returned by
\code{type()
}).
35 \begin{datadesc
}{IntType
}
36 The type of integers (e.g.
\code{1}).
39 \begin{datadesc
}{LongType
}
40 The type of long integers (e.g.
\code{1L}).
43 \begin{datadesc
}{FloatType
}
44 The type of floating point numbers (e.g.
\code{1.0}).
47 \begin{datadesc
}{StringType
}
48 The type of character strings (e.g.
\code{'Spam'
}).
51 \begin{datadesc
}{TupleType
}
52 The type of tuples (e.g.
\code{(
1,
2,
3, 'Spam')
}).
55 \begin{datadesc
}{ListType
}
56 The type of lists (e.g.
\code{[0,
1,
2,
3]}).
59 \begin{datadesc
}{DictType
}
60 The type of dictionaries (e.g.
\code{\
{'Bacon':
1, 'Ham':
0\
}}).
63 \begin{datadesc
}{DictionaryType
}
64 An alternative name for
\code{DictType
}.
67 \begin{datadesc
}{FunctionType
}
68 The type of user-defined functions and lambdas.
71 \begin{datadesc
}{LambdaType
}
72 An alternative name for
\code{FunctionType
}.
75 \begin{datadesc
}{CodeType
}
76 The type for code objects such as returned by
\code{compile()
}.
79 \begin{datadesc
}{ClassType
}
80 The type of user-defined classes.
83 \begin{datadesc
}{InstanceType
}
84 The type of instances of user-defined classes.
87 \begin{datadesc
}{MethodType
}
88 The type of methods of user-defined class instances.
91 \begin{datadesc
}{UnboundMethodType
}
92 An alternative name for
\code{MethodType
}.
95 \begin{datadesc
}{BuiltinFunctionType
}
96 The type of built-in functions like
\code{len
} or
\code{sys.exit
}.
99 \begin{datadesc
}{BuiltinMethodType
}
100 An alternative name for
\code{BuiltinFunction
}.
103 \begin{datadesc
}{ModuleType
}
107 \begin{datadesc
}{FileType
}
108 The type of open file objects such as
\code{sys.stdout
}.
111 \begin{datadesc
}{XRangeType
}
112 The type of range objects returned by
\code{xrange()
}.
115 \begin{datadesc
}{TracebackType
}
116 The type of traceback objects such as found in
\code{sys.exc_traceback
}.
119 \begin{datadesc
}{FrameType
}
120 The type of frame objects such as found in
\code{tb.tb_frame
} if
121 \code{tb
} is a traceback object.