This commit was manufactured by cvs2svn to create tag 'r221c2'.
[python/dscho.git] / Doc / lib / libtypes.tex
blob3f2a73fbf0ab053808b784ff3d871c7d775bc74a
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}).
52 \end{datadesc}
54 \begin{datadesc}{StringType}
55 The type of character strings (e.g. \code{'Spam'}).
56 \end{datadesc}
58 \begin{datadesc}{UnicodeType}
59 The type of Unicode character strings (e.g. \code{u'Spam'}).
60 \end{datadesc}
62 \begin{datadesc}{TupleType}
63 The type of tuples (e.g. \code{(1, 2, 3, 'Spam')}).
64 \end{datadesc}
66 \begin{datadesc}{ListType}
67 The type of lists (e.g. \code{[0, 1, 2, 3]}).
68 \end{datadesc}
70 \begin{datadesc}{DictType}
71 The type of dictionaries (e.g. \code{\{'Bacon': 1, 'Ham': 0\}}).
72 \end{datadesc}
74 \begin{datadesc}{DictionaryType}
75 An alternate name for \code{DictType}.
76 \end{datadesc}
78 \begin{datadesc}{FunctionType}
79 The type of user-defined functions and lambdas.
80 \end{datadesc}
82 \begin{datadesc}{LambdaType}
83 An alternate name for \code{FunctionType}.
84 \end{datadesc}
86 \begin{datadesc}{GeneratorType}
87 The type of generator-iterator objects, produced by calling a
88 generator function.
89 \versionadded{2.2}
90 \end{datadesc}
92 \begin{datadesc}{CodeType}
93 The type for code objects such as returned by
94 \function{compile()}\bifuncindex{compile}.
95 \end{datadesc}
97 \begin{datadesc}{ClassType}
98 The type of user-defined classes.
99 \end{datadesc}
101 \begin{datadesc}{InstanceType}
102 The type of instances of user-defined classes.
103 \end{datadesc}
105 \begin{datadesc}{MethodType}
106 The type of methods of user-defined class instances.
107 \end{datadesc}
109 \begin{datadesc}{UnboundMethodType}
110 An alternate name for \code{MethodType}.
111 \end{datadesc}
113 \begin{datadesc}{BuiltinFunctionType}
114 The type of built-in functions like \function{len()} or
115 \function{sys.exit()}.
116 \end{datadesc}
118 \begin{datadesc}{BuiltinMethodType}
119 An alternate name for \code{BuiltinFunction}.
120 \end{datadesc}
122 \begin{datadesc}{ModuleType}
123 The type of modules.
124 \end{datadesc}
126 \begin{datadesc}{FileType}
127 The type of open file objects such as \code{sys.stdout}.
128 \end{datadesc}
130 \begin{datadesc}{XRangeType}
131 The type of range objects returned by
132 \function{xrange()}\bifuncindex{xrange}.
133 \end{datadesc}
135 \begin{datadesc}{SliceType}
136 The type of objects returned by
137 \function{slice()}\bifuncindex{slice}.
138 \end{datadesc}
140 \begin{datadesc}{EllipsisType}
141 The type of \code{Ellipsis}.
142 \end{datadesc}
144 \begin{datadesc}{TracebackType}
145 The type of traceback objects such as found in
146 \code{sys.exc_traceback}.
147 \end{datadesc}
149 \begin{datadesc}{FrameType}
150 The type of frame objects such as found in \code{tb.tb_frame} if
151 \code{tb} is a traceback object.
152 \end{datadesc}
154 \begin{datadesc}{BufferType}
155 The type of buffer objects created by the
156 \function{buffer()}\bifuncindex{buffer} function.
157 \end{datadesc}
159 \begin{datadesc}{StringTypes}
160 A list containing \var{StringType} and \var{UnicodeType} used to
161 facilitate easier checking for any string object, e.g. \code{s in
162 types.StringTypes}.
163 \end{datadesc}