📄 module-types.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>3.4 types -- Names for all built-in types</title>
<META NAME="description" CONTENT="3.4 types -- Names for all built-in types">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-UserDict.html" tppabs="http://www.python.org/doc/current/lib/module-UserDict.html">
<LINK REL="previous" href="module-atexit.html" tppabs="http://www.python.org/doc/current/lib/module-atexit.html">
<LINK REL="up" href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html">
<LINK REL="next" href="module-UserDict.html" tppabs="http://www.python.org/doc/current/lib/module-UserDict.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="atexit-example.html" tppabs="http://www.python.org/doc/current/lib/atexit-example.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-UserDict.html" tppabs="http://www.python.org/doc/current/lib/module-UserDict.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="atexit-example.html" tppabs="http://www.python.org/doc/current/lib/atexit-example.html">3.3.1 atexit Example</A>
<b class="navlabel">Up:</b> <a class="sectref" href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html">3. Python Runtime Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-UserDict.html" tppabs="http://www.python.org/doc/current/lib/module-UserDict.html">3.5 UserDict </A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION005400000000000000000">
3.4 <tt class="module">types</tt> --
Names for all built-in types</A>
</H1>
<P>
<P>
This module defines names for all object types that are used by the
standard Python interpreter, but not for the types defined by various
extension modules. It is safe to use "<tt class="samp">from types import *</tt>" --
the module does not export any names besides the ones listed here.
New names exported by future versions of this module will all end in
"<tt class="samp">Type</tt>".
<P>
Typical use is for functions that do different things depending on
their argument types, like the following:
<P>
<dl><dd><pre class="verbatim">
from types import *
def delete(list, item):
if type(item) is IntType:
del list[item]
else:
list.remove(item)
</pre></dl>
<P>
The module defines the following names:
<P>
<dl><dt><b><a name='l2h-282'><tt>NoneType</tt></a></b>
<dd>
The type of <code>None</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-283'><tt>TypeType</tt></a></b>
<dd>
The type of type objects (such as returned by
<tt class="function">type()</tt>).
</dl>
<P>
<dl><dt><b><a name='l2h-284'><tt>IntType</tt></a></b>
<dd>
The type of integers (e.g. <code>1</code>).
</dl>
<P>
<dl><dt><b><a name='l2h-285'><tt>LongType</tt></a></b>
<dd>
The type of long integers (e.g. <code>1L</code>).
</dl>
<P>
<dl><dt><b><a name='l2h-286'><tt>FloatType</tt></a></b>
<dd>
The type of floating point numbers (e.g. <code>1.0</code>).
</dl>
<P>
<dl><dt><b><a name='l2h-287'><tt>ComplexType</tt></a></b>
<dd>
The type of complex numbers (e.g. <code>1.0j</code>).
</dl>
<P>
<dl><dt><b><a name='l2h-288'><tt>StringType</tt></a></b>
<dd>
The type of character strings (e.g. <code>'Spam'</code>).
</dl>
<P>
<dl><dt><b><a name='l2h-289'><tt>UnicodeType</tt></a></b>
<dd>
The type of Unicode character strings (e.g. <code>u'Spam'</code>).
</dl>
<P>
<dl><dt><b><a name='l2h-290'><tt>TupleType</tt></a></b>
<dd>
The type of tuples (e.g. <code>(1, 2, 3, 'Spam')</code>).
</dl>
<P>
<dl><dt><b><a name='l2h-291'><tt>ListType</tt></a></b>
<dd>
The type of lists (e.g. <code>[0, 1, 2, 3]</code>).
</dl>
<P>
<dl><dt><b><a name='l2h-292'><tt>DictType</tt></a></b>
<dd>
The type of dictionaries (e.g. <code>{'Bacon': 1, 'Ham': 0}</code>).
</dl>
<P>
<dl><dt><b><a name='l2h-293'><tt>DictionaryType</tt></a></b>
<dd>
An alternate name for <code>DictType</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-294'><tt>FunctionType</tt></a></b>
<dd>
The type of user-defined functions and lambdas.
</dl>
<P>
<dl><dt><b><a name='l2h-295'><tt>LambdaType</tt></a></b>
<dd>
An alternate name for <code>FunctionType</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-296'><tt>CodeType</tt></a></b>
<dd>
The type for code objects such as returned by
<tt class="function">compile()</tt>.
</dl>
<P>
<dl><dt><b><a name='l2h-297'><tt>ClassType</tt></a></b>
<dd>
The type of user-defined classes.
</dl>
<P>
<dl><dt><b><a name='l2h-298'><tt>InstanceType</tt></a></b>
<dd>
The type of instances of user-defined classes.
</dl>
<P>
<dl><dt><b><a name='l2h-299'><tt>MethodType</tt></a></b>
<dd>
The type of methods of user-defined class instances.
</dl>
<P>
<dl><dt><b><a name='l2h-300'><tt>UnboundMethodType</tt></a></b>
<dd>
An alternate name for <code>MethodType</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-301'><tt>BuiltinFunctionType</tt></a></b>
<dd>
The type of built-in functions like <tt class="function">len()</tt> or
<tt class="function">sys.exit()</tt>.
</dl>
<P>
<dl><dt><b><a name='l2h-302'><tt>BuiltinMethodType</tt></a></b>
<dd>
An alternate name for <code>BuiltinFunction</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-303'><tt>ModuleType</tt></a></b>
<dd>
The type of modules.
</dl>
<P>
<dl><dt><b><a name='l2h-304'><tt>FileType</tt></a></b>
<dd>
The type of open file objects such as <code>sys.stdout</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-305'><tt>XRangeType</tt></a></b>
<dd>
The type of range objects returned by
<tt class="function">xrange()</tt>.
</dl>
<P>
<dl><dt><b><a name='l2h-306'><tt>SliceType</tt></a></b>
<dd>
The type of objects returned by
<tt class="function">slice()</tt>.
</dl>
<P>
<dl><dt><b><a name='l2h-307'><tt>EllipsisType</tt></a></b>
<dd>
The type of <code>Ellipsis</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-308'><tt>TracebackType</tt></a></b>
<dd>
The type of traceback objects such as found in
<code>sys.exc_traceback</code>.
</dl>
<P>
<dl><dt><b><a name='l2h-309'><tt>FrameType</tt></a></b>
<dd>
The type of frame objects such as found in <code>tb.tb_frame</code> if
<code>tb</code> is a traceback object.
</dl>
<P>
<dl><dt><b><a name='l2h-310'><tt>BufferType</tt></a></b>
<dd>
The type of buffer objects created by the
<tt class="function">buffer()</tt> function.
</dl>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="atexit-example.html" tppabs="http://www.python.org/doc/current/lib/atexit-example.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-UserDict.html" tppabs="http://www.python.org/doc/current/lib/module-UserDict.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="atexit-example.html" tppabs="http://www.python.org/doc/current/lib/atexit-example.html">3.3.1 atexit Example</A>
<b class="navlabel">Up:</b> <a class="sectref" href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html">3. Python Runtime Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-UserDict.html" tppabs="http://www.python.org/doc/current/lib/module-UserDict.html">3.5 UserDict </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -