blob: 8ade4a6be956aa18e0fe0a49e9e2b22fbde2cb7e [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{types} ---
Fred Drake38e5d272000-04-03 20:13:55 +00002 Names for all built-in types}
3
Fred Drake78a6ddb1998-07-24 14:27:22 +00004\declaremodule{standard}{types}
Fred Drake78a6ddb1998-07-24 14:27:22 +00005\modulesynopsis{Names for all built-in types.}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00006
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007
Fred Drake78a6ddb1998-07-24 14:27:22 +00008This module defines names for all object types that are used by the
9standard Python interpreter, but not for the types defined by various
10extension modules. It is safe to use \samp{from types import *} ---
11the module does not export any names besides the ones listed here.
12New names exported by future versions of this module will all end in
13\samp{Type}.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000014
Fred Drake78a6ddb1998-07-24 14:27:22 +000015Typical use is for functions that do different things depending on
16their argument types, like the following:
Fred Drake1a855fa1998-03-16 05:23:50 +000017
Fred Drake19479911998-02-13 06:58:54 +000018\begin{verbatim}
Fred Drake78a6ddb1998-07-24 14:27:22 +000019from types import *
20def delete(list, item):
21 if type(item) is IntType:
22 del list[item]
23 else:
24 list.remove(item)
Fred Drake19479911998-02-13 06:58:54 +000025\end{verbatim}
Fred Drake1a855fa1998-03-16 05:23:50 +000026
Fred Drake78a6ddb1998-07-24 14:27:22 +000027The module defines the following names:
Guido van Rossum17383111994-04-21 10:32:28 +000028
Fred Drake78a6ddb1998-07-24 14:27:22 +000029\begin{datadesc}{NoneType}
30The type of \code{None}.
31\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000032
Fred Drake78a6ddb1998-07-24 14:27:22 +000033\begin{datadesc}{TypeType}
34The type of type objects (such as returned by
35\function{type()}\bifuncindex{type}).
36\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000037
Fred Drake78a6ddb1998-07-24 14:27:22 +000038\begin{datadesc}{IntType}
39The type of integers (e.g. \code{1}).
40\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000041
Fred Drake78a6ddb1998-07-24 14:27:22 +000042\begin{datadesc}{LongType}
43The type of long integers (e.g. \code{1L}).
44\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000045
Fred Drake78a6ddb1998-07-24 14:27:22 +000046\begin{datadesc}{FloatType}
47The type of floating point numbers (e.g. \code{1.0}).
48\end{datadesc}
Guido van Rossum3a0d8501997-06-02 17:18:00 +000049
Guido van Rossum1eb200d1998-07-24 15:01:05 +000050\begin{datadesc}{ComplexType}
51The type of complex numbers (e.g. \code{1.0j}).
52\end{datadesc}
53
Fred Drake78a6ddb1998-07-24 14:27:22 +000054\begin{datadesc}{StringType}
55The type of character strings (e.g. \code{'Spam'}).
56\end{datadesc}
Guido van Rossum3a0d8501997-06-02 17:18:00 +000057
Fred Drake0b721162000-04-06 15:05:04 +000058\begin{datadesc}{UnicodeType}
59The type of Unicode character strings (e.g. \code{u'Spam'}).
60\end{datadesc}
61
Fred Drake78a6ddb1998-07-24 14:27:22 +000062\begin{datadesc}{TupleType}
63The type of tuples (e.g. \code{(1, 2, 3, 'Spam')}).
64\end{datadesc}
Guido van Rossum97ea1161998-06-30 15:56:23 +000065
Fred Drake78a6ddb1998-07-24 14:27:22 +000066\begin{datadesc}{ListType}
67The type of lists (e.g. \code{[0, 1, 2, 3]}).
68\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000069
Fred Drake78a6ddb1998-07-24 14:27:22 +000070\begin{datadesc}{DictType}
71The type of dictionaries (e.g. \code{\{'Bacon': 1, 'Ham': 0\}}).
72\end{datadesc}
Fred Drakec3e45491998-02-19 20:22:13 +000073
Fred Drake78a6ddb1998-07-24 14:27:22 +000074\begin{datadesc}{DictionaryType}
75An alternate name for \code{DictType}.
76\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000077
Fred Drake78a6ddb1998-07-24 14:27:22 +000078\begin{datadesc}{FunctionType}
79The type of user-defined functions and lambdas.
80\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000081
Fred Drake78a6ddb1998-07-24 14:27:22 +000082\begin{datadesc}{LambdaType}
83An alternate name for \code{FunctionType}.
84\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000085
Fred Drake78a6ddb1998-07-24 14:27:22 +000086\begin{datadesc}{CodeType}
87The type for code objects such as returned by
88\function{compile()}\bifuncindex{compile}.
89\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000090
Fred Drake78a6ddb1998-07-24 14:27:22 +000091\begin{datadesc}{ClassType}
92The type of user-defined classes.
93\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000094
Fred Drake78a6ddb1998-07-24 14:27:22 +000095\begin{datadesc}{InstanceType}
96The type of instances of user-defined classes.
97\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000098
Fred Drake78a6ddb1998-07-24 14:27:22 +000099\begin{datadesc}{MethodType}
100The type of methods of user-defined class instances.
101\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000102
Fred Drake78a6ddb1998-07-24 14:27:22 +0000103\begin{datadesc}{UnboundMethodType}
104An alternate name for \code{MethodType}.
105\end{datadesc}
Guido van Rossum6102b511997-05-28 19:32:11 +0000106
Fred Drake78a6ddb1998-07-24 14:27:22 +0000107\begin{datadesc}{BuiltinFunctionType}
108The type of built-in functions like \function{len()} or
109\function{sys.exit()}.
110\end{datadesc}
Barry Warsawdc0f00a1997-10-06 17:50:48 +0000111
Fred Drake78a6ddb1998-07-24 14:27:22 +0000112\begin{datadesc}{BuiltinMethodType}
113An alternate name for \code{BuiltinFunction}.
114\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000115
Fred Drake78a6ddb1998-07-24 14:27:22 +0000116\begin{datadesc}{ModuleType}
117The type of modules.
118\end{datadesc}
Fred Drakec3e45491998-02-19 20:22:13 +0000119
Fred Drake78a6ddb1998-07-24 14:27:22 +0000120\begin{datadesc}{FileType}
121The type of open file objects such as \code{sys.stdout}.
122\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000123
Fred Drake78a6ddb1998-07-24 14:27:22 +0000124\begin{datadesc}{XRangeType}
125The type of range objects returned by
126\function{xrange()}\bifuncindex{xrange}.
127\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000128
Guido van Rossum1eb200d1998-07-24 15:01:05 +0000129\begin{datadesc}{SliceType}
130The type of objects returned by
131\function{slice()}\bifuncindex{slice}.
132\end{datadesc}
133
134\begin{datadesc}{EllipsisType}
135The type of \code{Ellipsis}.
136\end{datadesc}
137
Fred Drake78a6ddb1998-07-24 14:27:22 +0000138\begin{datadesc}{TracebackType}
139The type of traceback objects such as found in
140\code{sys.exc_traceback}.
141\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000142
Fred Drake78a6ddb1998-07-24 14:27:22 +0000143\begin{datadesc}{FrameType}
144The type of frame objects such as found in \code{tb.tb_frame} if
145\code{tb} is a traceback object.
146\end{datadesc}
Fred Drake38e5d272000-04-03 20:13:55 +0000147
148\begin{datadesc}{BufferType}
149The type of buffer objects created by the
150\function{buffer()}\bifuncindex{buffer} function.
151\end{datadesc}