blob: 3f2a73fbf0ab053808b784ff3d871c7d775bc74a [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
Tim Peters3e7b1a02001-06-25 19:46:25 +000086\begin{datadesc}{GeneratorType}
87The type of generator-iterator objects, produced by calling a
88generator function.
89\versionadded{2.2}
90\end{datadesc}
91
Fred Drake78a6ddb1998-07-24 14:27:22 +000092\begin{datadesc}{CodeType}
93The type for code objects such as returned by
94\function{compile()}\bifuncindex{compile}.
95\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000096
Fred Drake78a6ddb1998-07-24 14:27:22 +000097\begin{datadesc}{ClassType}
98The type of user-defined classes.
99\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000100
Fred Drake78a6ddb1998-07-24 14:27:22 +0000101\begin{datadesc}{InstanceType}
102The type of instances of user-defined classes.
103\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000104
Fred Drake78a6ddb1998-07-24 14:27:22 +0000105\begin{datadesc}{MethodType}
106The type of methods of user-defined class instances.
107\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000108
Fred Drake78a6ddb1998-07-24 14:27:22 +0000109\begin{datadesc}{UnboundMethodType}
110An alternate name for \code{MethodType}.
111\end{datadesc}
Guido van Rossum6102b511997-05-28 19:32:11 +0000112
Fred Drake78a6ddb1998-07-24 14:27:22 +0000113\begin{datadesc}{BuiltinFunctionType}
114The type of built-in functions like \function{len()} or
115\function{sys.exit()}.
116\end{datadesc}
Barry Warsawdc0f00a1997-10-06 17:50:48 +0000117
Fred Drake78a6ddb1998-07-24 14:27:22 +0000118\begin{datadesc}{BuiltinMethodType}
119An alternate name for \code{BuiltinFunction}.
120\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000121
Fred Drake78a6ddb1998-07-24 14:27:22 +0000122\begin{datadesc}{ModuleType}
123The type of modules.
124\end{datadesc}
Fred Drakec3e45491998-02-19 20:22:13 +0000125
Fred Drake78a6ddb1998-07-24 14:27:22 +0000126\begin{datadesc}{FileType}
127The type of open file objects such as \code{sys.stdout}.
128\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000129
Fred Drake78a6ddb1998-07-24 14:27:22 +0000130\begin{datadesc}{XRangeType}
131The type of range objects returned by
132\function{xrange()}\bifuncindex{xrange}.
133\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000134
Guido van Rossum1eb200d1998-07-24 15:01:05 +0000135\begin{datadesc}{SliceType}
136The type of objects returned by
137\function{slice()}\bifuncindex{slice}.
138\end{datadesc}
139
140\begin{datadesc}{EllipsisType}
141The type of \code{Ellipsis}.
142\end{datadesc}
143
Fred Drake78a6ddb1998-07-24 14:27:22 +0000144\begin{datadesc}{TracebackType}
145The type of traceback objects such as found in
146\code{sys.exc_traceback}.
147\end{datadesc}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +0000148
Fred Drake78a6ddb1998-07-24 14:27:22 +0000149\begin{datadesc}{FrameType}
150The type of frame objects such as found in \code{tb.tb_frame} if
151\code{tb} is a traceback object.
152\end{datadesc}
Fred Drake38e5d272000-04-03 20:13:55 +0000153
154\begin{datadesc}{BufferType}
155The type of buffer objects created by the
156\function{buffer()}\bifuncindex{buffer} function.
157\end{datadesc}
Skip Montanaroc7ba0c42001-09-29 13:49:41 +0000158
159\begin{datadesc}{StringTypes}
Skip Montanaroa1c36622001-09-29 13:53:21 +0000160A list containing \var{StringType} and \var{UnicodeType} used to
161facilitate easier checking for any string object, e.g. \code{s in
162types.StringTypes}.
Skip Montanaroc7ba0c42001-09-29 13:49:41 +0000163\end{datadesc}