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