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

📄 module-array.html

📁 一本很好的python的说明书,适合对python感兴趣的人
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>5.6 array -- Efficient arrays of numeric values</title>
<META NAME="description" CONTENT="5.6 array -- Efficient arrays of numeric values">
<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-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html">
<LINK REL="previous" href="module-bisect.html" tppabs="http://www.python.org/doc/current/lib/module-bisect.html">
<LINK REL="up" href="misc.html" tppabs="http://www.python.org/doc/current/lib/misc.html">
<LINK REL="next" href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="bisect-example.html" tppabs="http://www.python.org/doc/current/lib/bisect-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="misc.html" tppabs="http://www.python.org/doc/current/lib/misc.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-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.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="bisect-example.html" tppabs="http://www.python.org/doc/current/lib/bisect-example.html">5.5.1 Example</A>
<b class="navlabel">Up:</b> <a class="sectref" href="misc.html" tppabs="http://www.python.org/doc/current/lib/misc.html">5. Miscellaneous Services</A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-ConfigParser.html" tppabs="http://www.python.org/doc/current/lib/module-ConfigParser.html">5.7 ConfigParser  </A>
<br><hr></DIV>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION007600000000000000000">
5.6 <tt class="module">array</tt> --
         Efficient arrays of numeric values</A>
</H1>

<P>


<P>
This module defines a new object type which can efficiently represent
an array of basic values: characters, integers, floating point
numbers.  Arrays are sequence types and behave very much
like lists, except that the type of objects stored in them is
constrained.  The type is specified at object creation time by using a
<i class="dfn">type code</i>, which is a single character.  The following type
codes are defined:

<P>
<table border align="center" style="border-collapse: collapse">
  <thead>
    <tr>
      <th align="center"><b>Type code</b>&nbsp;</th>
      <th align="left"><b>C Type</b>&nbsp;</th>
      <th align="center"><b>Minimum size in bytes</b>&nbsp;</th>
    </thead>
  <tbody valign='baseline'>
    <tr><td align="center" valign="baseline"><code>'c'</code></td>
        <td align="left">character</td>
        <td align="center">1</td>
    <tr><td align="center" valign="baseline"><code>'b'</code></td>
        <td align="left">signed int</td>
        <td align="center">1</td>
    <tr><td align="center" valign="baseline"><code>'B'</code></td>
        <td align="left">unsigned int</td>
        <td align="center">1</td>
    <tr><td align="center" valign="baseline"><code>'h'</code></td>
        <td align="left">signed int</td>
        <td align="center">2</td>
    <tr><td align="center" valign="baseline"><code>'H'</code></td>
        <td align="left">unsigned int</td>
        <td align="center">2</td>
    <tr><td align="center" valign="baseline"><code>'i'</code></td>
        <td align="left">signed int</td>
        <td align="center">2</td>
    <tr><td align="center" valign="baseline"><code>'I'</code></td>
        <td align="left">unsigned int</td>
        <td align="center">2</td>
    <tr><td align="center" valign="baseline"><code>'l'</code></td>
        <td align="left">signed int</td>
        <td align="center">4</td>
    <tr><td align="center" valign="baseline"><code>'L'</code></td>
        <td align="left">unsigned int</td>
        <td align="center">4</td>
    <tr><td align="center" valign="baseline"><code>'f'</code></td>
        <td align="left">float</td>
        <td align="center">4</td>
    <tr><td align="center" valign="baseline"><code>'d'</code></td>
        <td align="left">double</td>
        <td align="center">8</td></tbody>
</table>

<P>
The actual representation of values is determined by the machine
architecture (strictly speaking, by the C implementation).  The actual
size can be accessed through the <tt class="member">itemsize</tt> attribute.  The values
stored  for <code>'L'</code> and <code>'I'</code> items will be represented as
Python long integers when retrieved, because Python's plain integer
type cannot represent the full range of C's unsigned (long) integers.

<P>
The module defines the following function and type object:

<P>
<dl><dt><b><a name='l2h-757'><tt class='function'>array</tt></a></b> (<var>typecode</var><big>[</big><var>, initializer</var><big>]</big>)
<dd>
Return a new array whose items are restricted by <var>typecode</var>, and
initialized from the optional <var>initializer</var> value, which must be a
list or a string.  The list or string is passed to the new array's
<tt class="method">fromlist()</tt> or <tt class="method">fromstring()</tt> method (see below) to add
initial items to the array.
</dl>

<P>
<dl><dt><b><a name='l2h-758'><tt>ArrayType</tt></a></b>
<dd>
Type object corresponding to the objects returned by
<tt class="function">array()</tt>.
</dl>

<P>
Array objects support the following data items and methods:

<P>
<dl><dt><b><a name='l2h-759'><tt class='member'>typecode</tt></a></b>
<dd>
The typecode character used to create the array.
</dl>

<P>
<dl><dt><b><a name='l2h-760'><tt class='member'>itemsize</tt></a></b>
<dd>
The length in bytes of one array item in the internal representation.
</dl>

<P>
<dl><dt><b><a name='l2h-761'><tt class='method'>append</tt></a></b> (<var>x</var>)
<dd>
Append a new item with value <var>x</var> to the end of the array.
</dl>

<P>
<dl><dt><b><a name='l2h-762'><tt class='method'>buffer_info</tt></a></b> ()
<dd>
Return a tuple <code>(<var>address</var>, <var>length</var>)</code> giving the current
memory address and the length in bytes of the buffer used to hold
array's contents.  This is occasionally useful when working with
low-level (and inherently unsafe) I/O interfaces that require memory
addresses, such as certain <tt class="cfunction">ioctl()</tt> operations.  The returned
numbers are valid as long as the array exists and no length-changing
operations are applied to it.
</dl>

<P>
<dl><dt><b><a name='l2h-763'><tt class='method'>byteswap</tt></a></b> ()
<dd>
``Byteswap'' all items of the array.  This is only supported for
values which are 1, 2, 4, or 8 bytes in size; for other types of
values, <tt class="exception">RuntimeError</tt> is raised.  It is useful when reading
data from a file written on a machine with a different byte order.
</dl>

<P>
<dl><dt><b><a name='l2h-764'><tt class='method'>count</tt></a></b> (<var>x</var>)
<dd>
Return the number of occurences of <var>x</var> in the array.
</dl>

<P>

⌨️ 快捷键说明

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