⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 built-in-funcs.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
📖 第 1 页 / 共 4 页
字号:
When a module is reloaded, its dictionary (containing the module's
global variables) is retained.  Redefinitions of names will override
the old definitions, so this is generally not a problem.  If the new
version of a module does not define a name that was defined by the old
version, the old definition remains.  This feature can be used to the
module's advantage if it maintains a global table or cache of objects
-- with a <tt class="keyword">try</tt> statement it can test for the table's presence
and skip its initialization if desired.

<P>
It is legal though generally not very useful to reload built-in or
dynamically loaded modules, except for <tt class="module">sys</tt>, <tt class="module">__main__</tt>
and <tt class="module">__builtin__</tt>.  In many cases, however, extension
modules are not designed to be initialized more than once, and may
fail in arbitrary ways when reloaded.

<P>
If a module imports objects from another module using <tt class="keyword">from</tt>
... <tt class="keyword">import</tt> ..., calling <tt class="function">reload()</tt> for
the other module does not redefine the objects imported from it --
one way around this is to re-execute the <tt class="keyword">from</tt> statement,
another is to use <tt class="keyword">import</tt> and qualified names
(<var>module</var>.<var>name</var>) instead.

<P>
If a module instantiates instances of a class, reloading the module
that defines the class does not affect the method definitions of the
instances -- they continue to use the old class definition.  The same
is true for derived classes.
</dl>

<P>
<dl><dt><b><a name='l2h-186'><tt class='function'>repr</tt></a></b> (<var>object</var>)
<dd>
Return a string containing a printable representation of an object.
This is the same value yielded by conversions (reverse quotes).
It is sometimes useful to be able to access this operation as an
ordinary function.  For many types, this function makes an attempt
to return a string that would yield an object with the same value
when passed to <tt class="function">eval()</tt>.
</dl>

<P>
<dl><dt><b><a name='l2h-187'><tt class='function'>round</tt></a></b> (<var>x</var><big>[</big><var>, n</var><big>]</big>)
<dd>
  Return the floating point value <var>x</var> rounded to <var>n</var> digits
  after the decimal point.  If <var>n</var> is omitted, it defaults to zero.
  The result is a floating point number.  Values are rounded to the
  closest multiple of 10 to the power minus <var>n</var>; if two multiples
  are equally close, rounding is done away from 0 (so e.g.
  <code>round(0.5)</code> is <code>1.0</code> and <code>round(-0.5)</code> is <code>-1.0</code>).
</dl>

<P>
<dl><dt><b><a name='l2h-188'><tt class='function'>setattr</tt></a></b> (<var>object, name, value</var>)
<dd>
  This is the counterpart of <tt class="function">getattr()</tt>.  The arguments are an
  object, a string and an arbitrary value.  The string may name an
  existing attribute or a new attribute.  The function assigns the
  value to the attribute, provided the object allows it.  For example,
  <code>setattr(<var>x</var>, '<var>foobar</var>', 123)</code> is equivalent to
  <code><var>x</var>.<var>foobar</var> = 123</code>.
</dl>

<P>
<dl><dt><b><a name='l2h-189'><tt class='function'>slice</tt></a></b> (<big>[</big><var>start,</var><big>]</big><var> stop</var><big>[</big><var>, step</var><big>]</big>)
<dd>
Return a slice object representing the set of indices specified by
<code>range(<var>start</var>, <var>stop</var>, <var>step</var>)</code>.  The <var>start</var>
and <var>step</var> arguments default to None.  Slice objects have
read-only data attributes <tt class="member">start</tt>, <tt class="member">stop</tt> and <tt class="member">step</tt>
which merely return the argument values (or their default).  They have
no other explicit functionality; however they are used by Numerical
Python and other third party extensions.
Slice objects are also generated when extended indexing syntax is
used, e.g. for "<tt class="samp">a[start:stop:step]</tt>" or "<tt class="samp">a[start:stop, i]</tt>".
</dl>

<P>
<dl><dt><b><a name='l2h-190'><tt class='function'>str</tt></a></b> (<var>object</var>)
<dd>
Return a string containing a nicely printable representation of an
object.  For strings, this returns the string itself.  The difference
with <code>repr(<var>object</var>)</code> is that <code>str(<var>object</var>)</code> does not
always attempt to return a string that is acceptable to <tt class="function">eval()</tt>;
its goal is to return a printable string.
</dl>

<P>
<dl><dt><b><a name='l2h-191'><tt class='function'>tuple</tt></a></b> (<var>sequence</var>)
<dd>
Return a tuple whose items are the same and in the same order as
<var>sequence</var>'s items.  If <var>sequence</var> is already a tuple, it
is returned unchanged.  For instance, <code>tuple('abc')</code> returns
returns <code>('a', 'b', 'c')</code> and <code>tuple([1, 2, 3])</code> returns
<code>(1, 2, 3)</code>.
</dl>

<P>
<dl><dt><b><a name='l2h-192'><tt class='function'>type</tt></a></b> (<var>object</var>)
<dd>
Return the type of an <var>object</var>.  The return value is a type
object.  The standard module <tt class="module">types</tt> defines names for all
built-in types.

For instance:

<P>
<dl><dd><pre class="verbatim">
&gt;&gt;&gt; import types
&gt;&gt;&gt; if type(x) == types.StringType: print "It's a string"
</pre></dl>
</dl>

<P>
<dl><dt><b><a name='l2h-193'><tt class='function'>unichr</tt></a></b> (<var>i</var>)
<dd>
Return the Unicode string of one character whose Unicode code is the
integer <var>i</var>, e.g., <code>unichr(97)</code> returns the string
<code>u'a'</code>.  This is the inverse of <tt class="function">ord()</tt> for Unicode
strings.  The argument must be in the range [0..65535], inclusive.
<tt class="exception">ValueError</tt> is raised otherwise.

New in version 2.0.

</dl>

<P>
<dl><dt><b><a name='l2h-194'><tt class='function'>unicode</tt></a></b> (<var>string</var><big>[</big><var>, encoding</var><big>[</big><var>, errors</var><big>]</big><big>]</big>)
<dd>
Decodes <var>string</var> using the codec for <var>encoding</var>.  Error
handling is done according to <var>errors</var>.  The default behavior is
to decode UTF-8 in strict mode, meaning that encoding errors raise
<tt class="exception">ValueError</tt>.  See also the <tt class='module'><a href="module-codecs.html" tppabs="http://www.python.org/doc/current/lib/module-codecs.html">codecs</a></tt> module.

New in version 2.0.

</dl>

<P>
<dl><dt><b><a name='l2h-195'><tt class='function'>vars</tt></a></b> (<big>[</big><var>object</var><big>]</big>)
<dd>
Without arguments, return a dictionary corresponding to the current
local symbol table.  With a module, class or class instance object as
argument (or anything else that has a <tt class="member">__dict__</tt> attribute),
returns a dictionary corresponding to the object's symbol table.
The returned dictionary should not be modified: the effects on the
corresponding symbol table are undefined.<A NAME="tex2html11"
  HREF="#foot2944"><SUP>2.11</SUP></A></dl>

<P>
<dl><dt><b><a name='l2h-196'><tt class='function'>xrange</tt></a></b> (<big>[</big><var>start,</var><big>]</big><var> stop</var><big>[</big><var>, step</var><big>]</big>)
<dd>
This function is very similar to <tt class="function">range()</tt>, but returns an
``xrange object'' instead of a list.  This is an opaque sequence type
which yields the same values as the corresponding list, without
actually storing them all simultaneously.  The advantage of
<tt class="function">xrange()</tt> over <tt class="function">range()</tt> is minimal (since
<tt class="function">xrange()</tt> still has to create the values when asked for
them) except when a very large range is used on a memory-starved
machine (e.g. MS-DOS) or when all of the range's elements are never
used (e.g. when the loop is usually terminated with <tt class="keyword">break</tt>).
</dl>

<P>
<dl><dt><b><a name='l2h-197'><tt class='function'>zip</tt></a></b> (<var>seq1, ...</var>)
<dd>
This function returns a list of tuples, where each tuple contains the
<var>i</var>-th element from each of the argument sequences.  At least one
sequence is required, otherwise a <tt class="exception">TypeError</tt> is raised.
The returned list is truncated in length to the length of the shortest
argument sequence.  When there are multiple argument sequences which
are all of the same length, <tt class="function">zip()</tt> is similar to
<tt class="function">map()</tt> with an initial argument of <code>None</code>.  With a
single sequence argument, it returns a list of 1-tuples.

New in version 2.0.

</dl>

<P>
<BR><HR><H4>Footnotes</H4>
<DL>
<DT><A NAME="foot2558">... module.</A><A NAME="foot2558"
 href="built-in-funcs.html#tex2html8" tppabs="http://www.python.org/doc/current/lib/built-in-funcs.html#tex2html8"><SUP>2.8</SUP></A>
<DD>It is used relatively
  rarely so does not warrant being made into a statement.

<DT><A NAME="foot2639">... zero.</A><A NAME="foot2639"
 href="built-in-funcs.html#tex2html9" tppabs="http://www.python.org/doc/current/lib/built-in-funcs.html#tex2html9"><SUP>2.9</SUP></A>
<DD>This is ugly -- the
  language definition should require truncation towards zero.

<DT><A NAME="foot2998">... used.</A><A NAME="foot2998"
 href="built-in-funcs.html#tex2html10" tppabs="http://www.python.org/doc/current/lib/built-in-funcs.html#tex2html10"><SUP>2.10</SUP></A>
<DD>
    Specifying a buffer size currently has no effect on systems that
    don't have <tt class="cfunction">setvbuf()</tt>.  The interface to specify the
    buffer size is not done using a method that calls
    <tt class="cfunction">setvbuf()</tt>, because that may dump core when called
    after any I/O has been performed, and there's no reliable way to
    determine whether this is the case.

<DT><A NAME="foot2944">... undefined.</A><A NAME="foot2944"
 href="built-in-funcs.html#tex2html11" tppabs="http://www.python.org/doc/current/lib/built-in-funcs.html#tex2html11"><SUP>2.11</SUP></A>
<DD>
  In the current implementation, local variable bindings cannot
  normally be affected this way, but variables retrieved from 
  other scopes (e.g. modules) can be.  This may change.

</DL>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-exceptions.html" tppabs="http://www.python.org/doc/current/lib/module-exceptions.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="builtin.html" tppabs="http://www.python.org/doc/current/lib/builtin.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="python.html" tppabs="http://www.python.org/doc/current/lib/python.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="module-exceptions.html" tppabs="http://www.python.org/doc/current/lib/module-exceptions.html">2.2 Built-in Exceptions</A>
<b class="navlabel">Up:</b> <a class="sectref" href="builtin.html" tppabs="http://www.python.org/doc/current/lib/builtin.html">2. Built-in Types, Exceptions</A>
<b class="navlabel">Next:</b> <a class="sectref" href="python.html" tppabs="http://www.python.org/doc/current/lib/python.html">3. Python Runtime Services</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 + -