This commit was manufactured by cvs2svn to create tag 'r223c1'.
[python/dscho.git] / Doc / lib / libtypes.tex
blob0e33126485e8bb557366f2ee826d56de145121ba
1 \section{\module{types} ---
2 Names for all built-in types}
4 \declaremodule{standard}{types}
5 \modulesynopsis{Names for all built-in types.}
8 This module defines names for all object types that are used by the
9 standard Python interpreter, but not for the types defined by various
10 extension modules. It is safe to use \samp{from types import *} ---
11 the module does not export any names besides the ones listed here.
12 New names exported by future versions of this module will all end in
13 \samp{Type}.
15 Typical use is for functions that do different things depending on
16 their argument types, like the following:
18 \begin{verbatim}
19 from types import *
20 def delete(list, item):
21 if type(item) is IntType:
22 del list[item]
23 else:
24 list.remove(item)
25 \end{verbatim}
27 The module defines the following names:
29 \begin{datadesc}{NoneType}
30 The type of \code{None}.
31 \end{datadesc}
33 \begin{datadesc}{TypeType}
34 The type of type objects (such as returned by
35 \function{type()}\bifuncindex{type}).
36 \end{datadesc}
38 \begin{datadesc}{IntType}
39 The type of integers (e.g. \code{1}).
40 \end{datadesc}
42 \begin{datadesc}{LongType}
43 The type of long integers (e.g. \code{1L}).
44 \end{datadesc}
46 \begin{datadesc}{FloatType}
47 The type of floating point numbers (e.g. \code{1.0}).
48 \end{datadesc}
50 \begin{datadesc}{ComplexType}
51 The type of complex numbers (e.g. \code{1.0j}). This is not defined
52 if Python was built without complex number support.
53 \end{datadesc}
55 \begin{datadesc}{StringType}
56 The type of character strings (e.g. \code{'Spam'}).
57 \end{datadesc}
59 \begin{datadesc}{UnicodeType}
60 The type of Unicode character strings (e.g. \code{u'Spam'}). This is
61 not defined if Python was built without Unicode support.
62 \end{datadesc}
64 \begin{datadesc}{TupleType}
65 The type of tuples (e.g. \code{(1, 2, 3, 'Spam')}).
66 \end{datadesc}
68 \begin{datadesc}{ListType}
69 The type of lists (e.g. \code{[0, 1, 2, 3]}).
70 \end{datadesc}
72 \begin{datadesc}{DictType}
73 The type of dictionaries (e.g. \code{\{'Bacon': 1, 'Ham': 0\}}).
74 \end{datadesc}
76 \begin{datadesc}{DictionaryType}
77 An alternate name for \code{DictType}.
78 \end{datadesc}
80 \begin{datadesc}{FunctionType}
81 The type of user-defined functions and lambdas.
82 \end{datadesc}
84 \begin{datadesc}{LambdaType}
85 An alternate name for \code{FunctionType}.
86 \end{datadesc}
88 \begin{datadesc}{GeneratorType}
89 The type of generator-iterator objects, produced by calling a
90 generator function.
91 \versionadded{2.2}
92 \end{datadesc}
94 \begin{datadesc}{CodeType}
95 The type for code objects such as returned by
96 \function{compile()}\bifuncindex{compile}.
97 \end{datadesc}
99 \begin{datadesc}{ClassType}
100 The type of user-defined classes.
101 \end{datadesc}
103 \begin{datadesc}{InstanceType}
104 The type of instances of user-defined classes.
105 \end{datadesc}
107 \begin{datadesc}{MethodType}
108 The type of methods of user-defined class instances.
109 \end{datadesc}
111 \begin{datadesc}{UnboundMethodType}
112 An alternate name for \code{MethodType}.
113 \end{datadesc}
115 \begin{datadesc}{BuiltinFunctionType}
116 The type of built-in functions like \function{len()} or
117 \function{sys.exit()}.
118 \end{datadesc}
120 \begin{datadesc}{BuiltinMethodType}
121 An alternate name for \code{BuiltinFunction}.
122 \end{datadesc}
124 \begin{datadesc}{ModuleType}
125 The type of modules.
126 \end{datadesc}
128 \begin{datadesc}{FileType}
129 The type of open file objects such as \code{sys.stdout}.
130 \end{datadesc}
132 \begin{datadesc}{XRangeType}
133 The type of range objects returned by
134 \function{xrange()}\bifuncindex{xrange}.
135 \end{datadesc}
137 \begin{datadesc}{SliceType}
138 The type of objects returned by
139 \function{slice()}\bifuncindex{slice}.
140 \end{datadesc}
142 \begin{datadesc}{EllipsisType}
143 The type of \code{Ellipsis}.
144 \end{datadesc}
146 \begin{datadesc}{TracebackType}
147 The type of traceback objects such as found in
148 \code{sys.exc_traceback}.
149 \end{datadesc}
151 \begin{datadesc}{FrameType}
152 The type of frame objects such as found in \code{tb.tb_frame} if
153 \code{tb} is a traceback object.
154 \end{datadesc}
156 \begin{datadesc}{BufferType}
157 The type of buffer objects created by the
158 \function{buffer()}\bifuncindex{buffer} function.
159 \end{datadesc}
161 \begin{datadesc}{StringTypes}
162 A sequence containing \code{StringType} and \code{UnicodeType} used to
163 facilitate easier checking for any string object. Using this is more
164 portable than using a sequence of the two string types constructed
165 elsewhere since it only contains \code{UnicodeType} if it has been
166 built in the running version of Python. For example:
167 \code{isinstance(s, types.StringTypes)}.
168 \versionadded{2.2}
169 \end{datadesc}