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

📄 built-in-funcs.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
📖 第 1 页 / 共 4 页
字号:
</pre></dl>
</dl>

<P>
<dl><dt><b><a name='l2h-155'><tt class='function'>divmod</tt></a></b> (<var>a, b</var>)
<dd>
  Take two numbers as arguments and return a pair of numbers consisting
  of their quotient and remainder when using long division.  With mixed
  operand types, the rules for binary arithmetic operators apply.  For
  plain and long integers, the result is the same as
  <code>(<var>a</var> / <var>b</var>, <var>a</var> % <var>b</var>)</code>.
  For floating point numbers the result is <code>(<var>q</var>, <var>a</var> %
  <var>b</var>)</code>, where <var>q</var> is usually <code>math.floor(<var>a</var> /
  <var>b</var>)</code> but may be 1 less than that.  In any case <code><var>q</var> *
  <var>b</var> + <var>a</var> % <var>b</var></code> is very close to <var>a</var>, if
  <code><var>a</var> % <var>b</var></code> is non-zero it has the same sign as
  <var>b</var>, and <code>0 &lt;= abs(<var>a</var> % <var>b</var>) &lt; abs(<var>b</var>)</code>.
</dl>

<P>
<dl><dt><b><a name='l2h-156'><tt class='function'>eval</tt></a></b> (<var>expression</var><big>[</big><var>, globals</var><big>[</big><var>, locals</var><big>]</big><big>]</big>)
<dd>
  The arguments are a string and two optional dictionaries.  The
  <var>expression</var> argument is parsed and evaluated as a Python
  expression (technically speaking, a condition list) using the
  <var>globals</var> and <var>locals</var> dictionaries as global and local name
  space.  If the <var>locals</var> dictionary is omitted it defaults to
  the <var>globals</var> dictionary.  If both dictionaries are omitted, the
  expression is executed in the environment where <tt class="keyword">eval</tt> is
  called.  The return value is the result of the evaluated expression.
  Syntax errors are reported as exceptions.  Example:

<P>
<dl><dd><pre class="verbatim">
&gt;&gt;&gt; x = 1
&gt;&gt;&gt; print eval('x+1')
2
</pre></dl>

<P>
This function can also be used to execute arbitrary code objects
  (e.g. created by <tt class="function">compile()</tt>).  In this case pass a code
  object instead of a string.  The code object must have been compiled
  passing <code>'eval'</code> to the <var>kind</var> argument.

<P>
Hints: dynamic execution of statements is supported by the
  <tt class="keyword">exec</tt> statement.  Execution of statements from a file is
  supported by the <tt class="function">execfile()</tt> function.  The
  <tt class="function">globals()</tt> and <tt class="function">locals()</tt> functions returns the
  current global and local dictionary, respectively, which may be
  useful to pass around for use by <tt class="function">eval()</tt> or
  <tt class="function">execfile()</tt>.
</dl>

<P>
<dl><dt><b><a name='l2h-157'><tt class='function'>execfile</tt></a></b> (<var>file</var><big>[</big><var>, globals</var><big>[</big><var>, locals</var><big>]</big><big>]</big>)
<dd>
  This function is similar to the
  <tt class="keyword">exec</tt> statement, but parses a file instead of a string.  It
  is different from the <tt class="keyword">import</tt> statement in that it does not
  use the module administration -- it reads the file unconditionally
  and does not create a new module.<A NAME="tex2html8"
  HREF="#foot2558"><SUP>2.8</SUP></A>
<P>
The arguments are a file name and two optional dictionaries.  The
  file is parsed and evaluated as a sequence of Python statements
  (similarly to a module) using the <var>globals</var> and <var>locals</var>
  dictionaries as global and local namespace.  If the <var>locals</var>
  dictionary is omitted it defaults to the <var>globals</var> dictionary.
  If both dictionaries are omitted, the expression is executed in the
  environment where <tt class="function">execfile()</tt> is called.  The return value is
  <code>None</code>.
</dl>

<P>
<dl><dt><b><a name='l2h-158'><tt class='function'>filter</tt></a></b> (<var>function, list</var>)
<dd>
Construct a list from those elements of <var>list</var> for which
<var>function</var> returns true.  If <var>list</var> is a string or a tuple,
the result also has that type; otherwise it is always a list.  If
<var>function</var> is <code>None</code>, the identity function is assumed,
i.e. all elements of <var>list</var> that are false (zero or empty) are
removed.
</dl>

<P>
<dl><dt><b><a name='l2h-159'><tt class='function'>float</tt></a></b> (<var>x</var>)
<dd>
  Convert a string or a number to floating point.  If the argument is a
  string, it must contain a possibly signed decimal or floating point
  number, possibly embedded in whitespace; this behaves identical to
  <code>string.atof(<var>x</var>)</code>.  Otherwise, the argument may be a plain
  or long integer or a floating point number, and a floating point
  number with the same value (within Python's floating point
  precision) is returned.

<P>
<b>Note:</b> When passing in a string, values for NaN
  and Infinity may be returned, depending on the
  underlying C library.  The specific set of strings accepted which
  cause these values to be returned depends entirely on the C library
  and is known to vary.
</dl>

<P>
<dl><dt><b><a name='l2h-160'><tt class='function'>getattr</tt></a></b> (<var>object, name</var><big>[</big><var>, default</var><big>]</big>)
<dd>
  Return the value of the named attributed of <var>object</var>.  <var>name</var>
  must be a string.  If the string is the name of one of the object's
  attributes, the result is the value of that attribute.  For example,
  <code>getattr(x, 'foobar')</code> is equivalent to <code>x.foobar</code>.  If the
  named attribute does not exist, <var>default</var> is returned if provided,
  otherwise <tt class="exception">AttributeError</tt> is raised.
</dl>

<P>
<dl><dt><b><a name='l2h-161'><tt class='function'>globals</tt></a></b> ()
<dd>
Return a dictionary representing the current global symbol table.
This is always the dictionary of the current module (inside a
function or method, this is the module where it is defined, not the
module from which it is called).
</dl>

<P>
<dl><dt><b><a name='l2h-162'><tt class='function'>hasattr</tt></a></b> (<var>object, name</var>)
<dd>
  The arguments are an object and a string.  The result is 1 if the
  string is the name of one of the object's attributes, 0 if not.
  (This is implemented by calling <code>getattr(<var>object</var>,
  <var>name</var>)</code> and seeing whether it raises an exception or not.)
</dl>

<P>
<dl><dt><b><a name='l2h-163'><tt class='function'>hash</tt></a></b> (<var>object</var>)
<dd>
  Return the hash value of the object (if it has one).  Hash values
  are integers.  They are used to quickly compare dictionary
  keys during a dictionary lookup.  Numeric values that compare equal
  have the same hash value (even if they are of different types, e.g.
  1 and 1.0).
</dl>

<P>
<dl><dt><b><a name='l2h-164'><tt class='function'>hex</tt></a></b> (<var>x</var>)
<dd>
  Convert an integer number (of any size) to a hexadecimal string.
  The result is a valid Python expression.  Note: this always yields
  an unsigned literal, e.g. on a 32-bit machine, <code>hex(-1)</code> yields
  <code>'0xffffffff'</code>.  When evaluated on a machine with the same
  word size, this literal is evaluated as -1; at a different word
  size, it may turn up as a large positive number or raise an
  <tt class="exception">OverflowError</tt> exception.
</dl>

<P>
<dl><dt><b><a name='l2h-165'><tt class='function'>id</tt></a></b> (<var>object</var>)
<dd>
  Return the `identity' of an object.  This is an integer (or long
  integer) which is guaranteed to be unique and constant for this
  object during its lifetime.  Two objects whose lifetimes are
  disjunct may have the same <tt class="function">id()</tt> value.  (Implementation
  note: this is the address of the object.)
</dl>

<P>
<dl><dt><b><a name='l2h-166'><tt class='function'>input</tt></a></b> (<big>[</big><var>prompt</var><big>]</big>)
<dd>
  Equivalent to <code>eval(raw_input(<var>prompt</var>))</code>.
  <b>Warning:</b> This function is not safe from user errors!  It
  expects a valid Python expression as input; if the input is not
  syntactically valid, a <tt class="exception">SyntaxError</tt> will be raised.
  Other exceptions may be raised if there is an error during
  evaluation.  (On the other hand, sometimes this is exactly what you
  need when writing a quick script for expert use.)

<P>
If the <tt class="module">readline</tt> module was loaded, then
  <tt class="function">input()</tt> will use it to provide elaborate line editing and
  history features.

<P>
Consider using the <tt class="function">raw_input()</tt> function for general input
  from users.
</dl>

<P>
<dl><dt><b><a name='l2h-167'><tt class='function'>int</tt></a></b> (<var>x</var><big>[</big><var>, radix</var><big>]</big>)
<dd>
  Convert a string or number to a plain integer.  If the argument is a
  string, it must contain a possibly signed decimal number
  representable as a Python integer, possibly embedded in whitespace;
  this behaves identical to <code>string.atoi(<var>x</var><big>[</big>,
  <var>radix</var><big>]</big>)</code>.  The <var>radix</var> parameter gives the base for the
  conversion and may be any integer in the range [2, 36].  If
  <var>radix</var> is specified and <var>x</var> is not a string,
  <tt class="exception">TypeError</tt> is raised.
  Otherwise, the argument may be a plain or
  long integer or a floating point number.  Conversion of floating
  point numbers to integers is defined by the C semantics; normally
  the conversion truncates towards zero.<A NAME="tex2html9"
  HREF="#foot2639"><SUP>2.9</SUP></A></dl>

<P>
<dl><dt><b><a name='l2h-168'><tt class='function'>intern</tt></a></b> (<var>string</var>)
<dd>
  Enter <var>string</var> in the table of ``interned'' strings and return
  the interned string - which is <var>string</var> itself or a copy.
  Interning strings is useful to gain a little performance on
  dictionary lookup - if the keys in a dictionary are interned, and
  the lookup key is interned, the key comparisons (after hashing) can
  be done by a pointer compare instead of a string compare.  Normally,
  the names used in Python programs are automatically interned, and
  the dictionaries used to hold module, class or instance attributes
  have interned keys.  Interned strings are immortal (i.e. never get
  garbage collected).
</dl>

<P>
<dl><dt><b><a name='l2h-169'><tt class='function'>isinstance</tt></a></b> (<var>object, class</var>)
<dd>
Return true if the <var>object</var> argument is an instance of the
<var>class</var> argument, or of a (direct or indirect) subclass thereof.
Also return true if <var>class</var> is a type object and <var>object</var> is
an object of that type.  If <var>object</var> is not a class instance or a
object of the given type, the function always returns false.  If
<var>class</var> is neither a class object nor a type object, a
<tt class="exception">TypeError</tt> exception is raised.
</dl>

<P>
<dl><dt><b><a name='l2h-170'><tt class='function'>issubclass</tt></a></b> (<var>class1, class2</var>)
<dd>
Return true if <var>class1</var> is a subclass (direct or indirect) of
<var>class2</var>.  A class is considered a subclass of itself.  If either
argument is not a class object, a <tt class="exception">TypeError</tt> exception is
raised.
</dl>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -