blob: d0f20c9db789bcb1aa19714c6e85e3df5c298beb [file] [log] [blame]
Guido van Rossum470be141995-03-17 16:07:09 +00001\section{Standard Module \sectcode{types}}
Guido van Rossuma12ef941995-02-27 17:53:25 +00002\stmodindex{types}
3
Guido van Rossumdc46c7f1995-03-01 15:38:16 +00004\renewcommand{\indexsubitem}{(in module types)}
5
Guido van Rossuma12ef941995-02-27 17:53:25 +00006This module defines names for all object types that are used by the
7standard Python interpreter (but not for the types defined by various
Guido van Rossumdc46c7f1995-03-01 15:38:16 +00008extension modules). It is safe to use ``\code{from types import *}'' ---
Guido van Rossuma12ef941995-02-27 17:53:25 +00009the module does not export any other names besides the ones listed
10here. New names exported by future versions of this module will
11all end in \code{Type}.
12
13Typical use is for functions that do different things depending on
14their argument types, like the following:
15
16\begin{verbatim}
17from types import *
18def delete(list, item):
19 if type(item) is IntType:
20 del list[item]
21 else:
22 list.remove(item)
23\end{verbatim}
24
25The module defines the following names:
26
27\begin{datadesc}{NoneType}
28The type of \code{None}.
29\end{datadesc}
30
31\begin{datadesc}{TypeType}
32The type of type objects (such as returned by \code{type()}).
33\end{datadesc}
34
35\begin{datadesc}{IntType}
36The type of integers (e.g. \code{1}).
37\end{datadesc}
38
39\begin{datadesc}{LongType}
40The type of long integers (e.g. \code{1L}).
41\end{datadesc}
42
43\begin{datadesc}{FloatType}
44The type of floating point numbers (e.g. \code{1.0}).
45\end{datadesc}
46
47\begin{datadesc}{StringType}
48The type of character strings (e.g. \code{'Spam'}).
49\end{datadesc}
50
51\begin{datadesc}{TupleType}
52The type of tuples (e.g. \code{(1, 2, 3, 'Spam')}).
53\end{datadesc}
54
55\begin{datadesc}{ListType}
56The type of lists (e.g. \code{[0, 1, 2, 3]}).
57\end{datadesc}
58
59\begin{datadesc}{DictType}
60The type of dictionaries (e.g. \code{\{'Bacon': 1, 'Ham': 0\}}).
61\end{datadesc}
62
63\begin{datadesc}{DictionaryType}
64An alternative name for \code{DictType}.
65\end{datadesc}
66
67\begin{datadesc}{FunctionType}
68The type of user-defined functions and lambdas.
69\end{datadesc}
70
71\begin{datadesc}{LambdaType}
72 An alternative name for \code{FunctionType}.
73\end{datadesc}
74
75\begin{datadesc}{CodeType}
76The type for code objects such as returned by \code{compile()}.
77\end{datadesc}
78
79\begin{datadesc}{ClassType}
80The type of user-defined classes.
81\end{datadesc}
82
83\begin{datadesc}{InstanceType}
84The type of instances of user-defined classes.
85\end{datadesc}
86
87\begin{datadesc}{MethodType}
88The type of methods of user-defined class instances.
89\end{datadesc}
90
91\begin{datadesc}{UnboundMethodType}
92An alternative name for \code{MethodType}.
93\end{datadesc}
94
95\begin{datadesc}{BuiltinFunctionType}
96The type of built-in functions like \code{len} or \code{sys.exit}.
97\end{datadesc}
98
99\begin{datadesc}{BuiltinMethodType}
100An alternative name for \code{BuiltinFunction}.
101\end{datadesc}
102
103\begin{datadesc}{ModuleType}
104The type of modules.
105\end{datadesc}
106
107\begin{datadesc}{FileType}
108The type of open file objects such as \code{sys.stdout}.
109\end{datadesc}
110
111\begin{datadesc}{XRangeType}
112The type of range objects returned by \code{xrange()}.
113\end{datadesc}
114
115\begin{datadesc}{TracebackType}
116The type of traceback objects such as found in \code{sys.exc_traceback}.
117\end{datadesc}
118
119\begin{datadesc}{FrameType}
120The type of frame objects such as found in \code{tb.tb_frame} if
121\code{tb} is a traceback object.
122\end{datadesc}