Added a test for the ability to specify a class attribute in Formatter configuration...
[python.git] / Doc / lib / libtypes.tex
blob19d2faa21b5748ee60f8807030fe6ab120407f7e
1 \section{\module{types} ---
2 Names for built-in types}
4 \declaremodule{standard}{types}
5 \modulesynopsis{Names for built-in types.}
8 This module defines names for some object types that are used by
9 the standard Python interpreter, but not for the types defined by various
10 extension modules. Also, it does not include some of the types that
11 arise during processing such as the \code{listiterator} type.
12 It is safe to use \samp{from types import *} ---
13 the module does not export any names besides the ones listed here.
14 New names exported by future versions of this module will all end in
15 \samp{Type}.
17 Typical use is for functions that do different things depending on
18 their argument types, like the following:
20 \begin{verbatim}
21 from types import *
22 def delete(mylist, item):
23 if type(item) is IntType:
24 del mylist[item]
25 else:
26 mylist.remove(item)
27 \end{verbatim}
29 Starting in Python 2.2, built-in factory functions such as
30 \function{int()} and \function{str()} are also names for the
31 corresponding types. This is now the preferred way to access
32 the type instead of using the \module{types} module. Accordingly,
33 the example above should be written as follows:
35 \begin{verbatim}
36 def delete(mylist, item):
37 if isinstance(item, int):
38 del mylist[item]
39 else:
40 mylist.remove(item)
41 \end{verbatim}
43 The module defines the following names:
45 \begin{datadesc}{NoneType}
46 The type of \code{None}.
47 \end{datadesc}
49 \begin{datadesc}{TypeType}
50 The type of type objects (such as returned by
51 \function{type()}\bifuncindex{type}).
52 \end{datadesc}
54 \begin{datadesc}{BooleanType}
55 The type of the \class{bool} values \code{True} and \code{False}; this
56 is an alias of the built-in \function{bool()} function.
57 \versionadded{2.3}
58 \end{datadesc}
60 \begin{datadesc}{IntType}
61 The type of integers (e.g. \code{1}).
62 \end{datadesc}
64 \begin{datadesc}{LongType}
65 The type of long integers (e.g. \code{1L}).
66 \end{datadesc}
68 \begin{datadesc}{FloatType}
69 The type of floating point numbers (e.g. \code{1.0}).
70 \end{datadesc}
72 \begin{datadesc}{ComplexType}
73 The type of complex numbers (e.g. \code{1.0j}). This is not defined
74 if Python was built without complex number support.
75 \end{datadesc}
77 \begin{datadesc}{StringType}
78 The type of character strings (e.g. \code{'Spam'}).
79 \end{datadesc}
81 \begin{datadesc}{UnicodeType}
82 The type of Unicode character strings (e.g. \code{u'Spam'}). This is
83 not defined if Python was built without Unicode support.
84 \end{datadesc}
86 \begin{datadesc}{TupleType}
87 The type of tuples (e.g. \code{(1, 2, 3, 'Spam')}).
88 \end{datadesc}
90 \begin{datadesc}{ListType}
91 The type of lists (e.g. \code{[0, 1, 2, 3]}).
92 \end{datadesc}
94 \begin{datadesc}{DictType}
95 The type of dictionaries (e.g. \code{\{'Bacon': 1, 'Ham': 0\}}).
96 \end{datadesc}
98 \begin{datadesc}{DictionaryType}
99 An alternate name for \code{DictType}.
100 \end{datadesc}
102 \begin{datadesc}{FunctionType}
103 The type of user-defined functions and lambdas.
104 \end{datadesc}
106 \begin{datadesc}{LambdaType}
107 An alternate name for \code{FunctionType}.
108 \end{datadesc}
110 \begin{datadesc}{GeneratorType}
111 The type of generator-iterator objects, produced by calling a
112 generator function.
113 \versionadded{2.2}
114 \end{datadesc}
116 \begin{datadesc}{CodeType}
117 The type for code objects such as returned by
118 \function{compile()}\bifuncindex{compile}.
119 \end{datadesc}
121 \begin{datadesc}{ClassType}
122 The type of user-defined classes.
123 \end{datadesc}
125 \begin{datadesc}{InstanceType}
126 The type of instances of user-defined classes.
127 \end{datadesc}
129 \begin{datadesc}{MethodType}
130 The type of methods of user-defined class instances.
131 \end{datadesc}
133 \begin{datadesc}{UnboundMethodType}
134 An alternate name for \code{MethodType}.
135 \end{datadesc}
137 \begin{datadesc}{BuiltinFunctionType}
138 The type of built-in functions like \function{len()} or
139 \function{sys.exit()}.
140 \end{datadesc}
142 \begin{datadesc}{BuiltinMethodType}
143 An alternate name for \code{BuiltinFunction}.
144 \end{datadesc}
146 \begin{datadesc}{ModuleType}
147 The type of modules.
148 \end{datadesc}
150 \begin{datadesc}{FileType}
151 The type of open file objects such as \code{sys.stdout}.
152 \end{datadesc}
154 \begin{datadesc}{XRangeType}
155 The type of range objects returned by
156 \function{xrange()}\bifuncindex{xrange}.
157 \end{datadesc}
159 \begin{datadesc}{SliceType}
160 The type of objects returned by
161 \function{slice()}\bifuncindex{slice}.
162 \end{datadesc}
164 \begin{datadesc}{EllipsisType}
165 The type of \code{Ellipsis}.
166 \end{datadesc}
168 \begin{datadesc}{TracebackType}
169 The type of traceback objects such as found in
170 \code{sys.exc_traceback}.
171 \end{datadesc}
173 \begin{datadesc}{FrameType}
174 The type of frame objects such as found in \code{tb.tb_frame} if
175 \code{tb} is a traceback object.
176 \end{datadesc}
178 \begin{datadesc}{BufferType}
179 The type of buffer objects created by the
180 \function{buffer()}\bifuncindex{buffer} function.
181 \end{datadesc}
183 \begin{datadesc}{StringTypes}
184 A sequence containing \code{StringType} and \code{UnicodeType} used to
185 facilitate easier checking for any string object. Using this is more
186 portable than using a sequence of the two string types constructed
187 elsewhere since it only contains \code{UnicodeType} if it has been
188 built in the running version of Python. For example:
189 \code{isinstance(s, types.StringTypes)}.
190 \versionadded{2.2}
191 \end{datadesc}