Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{types} --- |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 2 | Names for all built-in types} |
| 3 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 4 | \declaremodule{standard}{types} |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 5 | \modulesynopsis{Names for all built-in types.} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 7 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 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}. |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 14 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 15 | Typical use is for functions that do different things depending on |
| 16 | their argument types, like the following: |
Fred Drake | 1a855fa | 1998-03-16 05:23:50 +0000 | [diff] [blame] | 17 | |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 18 | \begin{verbatim} |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 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) |
Fred Drake | 1947991 | 1998-02-13 06:58:54 +0000 | [diff] [blame] | 25 | \end{verbatim} |
Fred Drake | 1a855fa | 1998-03-16 05:23:50 +0000 | [diff] [blame] | 26 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 27 | The module defines the following names: |
Guido van Rossum | 1738311 | 1994-04-21 10:32:28 +0000 | [diff] [blame] | 28 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 29 | \begin{datadesc}{NoneType} |
| 30 | The type of \code{None}. |
| 31 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 32 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 33 | \begin{datadesc}{TypeType} |
| 34 | The type of type objects (such as returned by |
| 35 | \function{type()}\bifuncindex{type}). |
| 36 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 37 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 38 | \begin{datadesc}{IntType} |
| 39 | The type of integers (e.g. \code{1}). |
| 40 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 41 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 42 | \begin{datadesc}{LongType} |
| 43 | The type of long integers (e.g. \code{1L}). |
| 44 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 45 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 46 | \begin{datadesc}{FloatType} |
| 47 | The type of floating point numbers (e.g. \code{1.0}). |
| 48 | \end{datadesc} |
Guido van Rossum | 3a0d850 | 1997-06-02 17:18:00 +0000 | [diff] [blame] | 49 | |
Guido van Rossum | 1eb200d | 1998-07-24 15:01:05 +0000 | [diff] [blame] | 50 | \begin{datadesc}{ComplexType} |
| 51 | The type of complex numbers (e.g. \code{1.0j}). |
| 52 | \end{datadesc} |
| 53 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 54 | \begin{datadesc}{StringType} |
| 55 | The type of character strings (e.g. \code{'Spam'}). |
| 56 | \end{datadesc} |
Guido van Rossum | 3a0d850 | 1997-06-02 17:18:00 +0000 | [diff] [blame] | 57 | |
Fred Drake | 0b72116 | 2000-04-06 15:05:04 +0000 | [diff] [blame] | 58 | \begin{datadesc}{UnicodeType} |
| 59 | The type of Unicode character strings (e.g. \code{u'Spam'}). |
| 60 | \end{datadesc} |
| 61 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 62 | \begin{datadesc}{TupleType} |
| 63 | The type of tuples (e.g. \code{(1, 2, 3, 'Spam')}). |
| 64 | \end{datadesc} |
Guido van Rossum | 97ea116 | 1998-06-30 15:56:23 +0000 | [diff] [blame] | 65 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 66 | \begin{datadesc}{ListType} |
| 67 | The type of lists (e.g. \code{[0, 1, 2, 3]}). |
| 68 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 69 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 70 | \begin{datadesc}{DictType} |
| 71 | The type of dictionaries (e.g. \code{\{'Bacon': 1, 'Ham': 0\}}). |
| 72 | \end{datadesc} |
Fred Drake | c3e4549 | 1998-02-19 20:22:13 +0000 | [diff] [blame] | 73 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 74 | \begin{datadesc}{DictionaryType} |
| 75 | An alternate name for \code{DictType}. |
| 76 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 77 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 78 | \begin{datadesc}{FunctionType} |
| 79 | The type of user-defined functions and lambdas. |
| 80 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 81 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 82 | \begin{datadesc}{LambdaType} |
| 83 | An alternate name for \code{FunctionType}. |
| 84 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 85 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 86 | \begin{datadesc}{CodeType} |
| 87 | The type for code objects such as returned by |
| 88 | \function{compile()}\bifuncindex{compile}. |
| 89 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 90 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 91 | \begin{datadesc}{ClassType} |
| 92 | The type of user-defined classes. |
| 93 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 94 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 95 | \begin{datadesc}{InstanceType} |
| 96 | The type of instances of user-defined classes. |
| 97 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 98 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 99 | \begin{datadesc}{MethodType} |
| 100 | The type of methods of user-defined class instances. |
| 101 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 102 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 103 | \begin{datadesc}{UnboundMethodType} |
| 104 | An alternate name for \code{MethodType}. |
| 105 | \end{datadesc} |
Guido van Rossum | 6102b51 | 1997-05-28 19:32:11 +0000 | [diff] [blame] | 106 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 107 | \begin{datadesc}{BuiltinFunctionType} |
| 108 | The type of built-in functions like \function{len()} or |
| 109 | \function{sys.exit()}. |
| 110 | \end{datadesc} |
Barry Warsaw | dc0f00a | 1997-10-06 17:50:48 +0000 | [diff] [blame] | 111 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 112 | \begin{datadesc}{BuiltinMethodType} |
| 113 | An alternate name for \code{BuiltinFunction}. |
| 114 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 115 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 116 | \begin{datadesc}{ModuleType} |
| 117 | The type of modules. |
| 118 | \end{datadesc} |
Fred Drake | c3e4549 | 1998-02-19 20:22:13 +0000 | [diff] [blame] | 119 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 120 | \begin{datadesc}{FileType} |
| 121 | The type of open file objects such as \code{sys.stdout}. |
| 122 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 123 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 124 | \begin{datadesc}{XRangeType} |
| 125 | The type of range objects returned by |
| 126 | \function{xrange()}\bifuncindex{xrange}. |
| 127 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 128 | |
Guido van Rossum | 1eb200d | 1998-07-24 15:01:05 +0000 | [diff] [blame] | 129 | \begin{datadesc}{SliceType} |
| 130 | The type of objects returned by |
| 131 | \function{slice()}\bifuncindex{slice}. |
| 132 | \end{datadesc} |
| 133 | |
| 134 | \begin{datadesc}{EllipsisType} |
| 135 | The type of \code{Ellipsis}. |
| 136 | \end{datadesc} |
| 137 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 138 | \begin{datadesc}{TracebackType} |
| 139 | The type of traceback objects such as found in |
| 140 | \code{sys.exc_traceback}. |
| 141 | \end{datadesc} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 142 | |
Fred Drake | 78a6ddb | 1998-07-24 14:27:22 +0000 | [diff] [blame] | 143 | \begin{datadesc}{FrameType} |
| 144 | The type of frame objects such as found in \code{tb.tb_frame} if |
| 145 | \code{tb} is a traceback object. |
| 146 | \end{datadesc} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 147 | |
| 148 | \begin{datadesc}{BufferType} |
| 149 | The type of buffer objects created by the |
| 150 | \function{buffer()}\bifuncindex{buffer} function. |
| 151 | \end{datadesc} |