📄 module-array.html
字号:
<dl><dt><b><a name='l2h-765'><tt class='method'>extend</tt></a></b> (<var>a</var>)
<dd>
Append array items from <var>a</var> to the end of the array.
</dl>
<P>
<dl><dt><b><a name='l2h-766'><tt class='method'>fromfile</tt></a></b> (<var>f, n</var>)
<dd>
Read <var>n</var> items (as machine values) from the file object <var>f</var>
and append them to the end of the array. If less than <var>n</var> items
are available, <tt class="exception">EOFError</tt> is raised, but the items that were
available are still inserted into the array. <var>f</var> must be a real
built-in file object; something else with a <tt class="method">read()</tt> method won't
do.
</dl>
<P>
<dl><dt><b><a name='l2h-767'><tt class='method'>fromlist</tt></a></b> (<var>list</var>)
<dd>
Append items from the list. This is equivalent to
"<tt class="samp">for x in <var>list</var>: a.append(x)</tt>"except that if there is a type error, the array is unchanged.
</dl>
<P>
<dl><dt><b><a name='l2h-768'><tt class='method'>fromstring</tt></a></b> (<var>s</var>)
<dd>
Appends items from the string, interpreting the string as an
array of machine values (i.e. as if it had been read from a
file using the <tt class="method">fromfile()</tt> method).
</dl>
<P>
<dl><dt><b><a name='l2h-769'><tt class='method'>index</tt></a></b> (<var>x</var>)
<dd>
Return the smallest <var>i</var> such that <var>i</var> is the index of
the first occurence of <var>x</var> in the array.
</dl>
<P>
<dl><dt><b><a name='l2h-770'><tt class='method'>insert</tt></a></b> (<var>i, x</var>)
<dd>
Insert a new item with value <var>x</var> in the array before position
<var>i</var>.
</dl>
<P>
<dl><dt><b><a name='l2h-771'><tt class='method'>pop</tt></a></b> (<big>[</big><var>i</var><big>]</big>)
<dd>
Removes the item with the index <var>i</var> from the array and returns
it. The optional argument defaults to <code>-1</code>, so that by default
the last item is removed and returned.
</dl>
<P>
<dl><dt><b><a name='l2h-772'><tt class='method'>read</tt></a></b> (<var>f, n</var>)
<dd>
<b>Deprecated since release 1.5.1.</b>
Use the <tt class="method">fromfile()</tt> method.<p>
Read <var>n</var> items (as machine values) from the file object <var>f</var>
and append them to the end of the array. If less than <var>n</var> items
are available, <tt class="exception">EOFError</tt> is raised, but the items that were
available are still inserted into the array. <var>f</var> must be a real
built-in file object; something else with a <tt class="method">read()</tt> method won't
do.
</dl>
<P>
<dl><dt><b><a name='l2h-773'><tt class='method'>remove</tt></a></b> (<var>x</var>)
<dd>
Remove the first occurence of <var>x</var> from the array.
</dl>
<P>
<dl><dt><b><a name='l2h-774'><tt class='method'>reverse</tt></a></b> ()
<dd>
Reverse the order of the items in the array.
</dl>
<P>
<dl><dt><b><a name='l2h-775'><tt class='method'>tofile</tt></a></b> (<var>f</var>)
<dd>
Write all items (as machine values) to the file object <var>f</var>.
</dl>
<P>
<dl><dt><b><a name='l2h-776'><tt class='method'>tolist</tt></a></b> ()
<dd>
Convert the array to an ordinary list with the same items.
</dl>
<P>
<dl><dt><b><a name='l2h-777'><tt class='method'>tostring</tt></a></b> ()
<dd>
Convert the array to an array of machine values and return the
string representation (the same sequence of bytes that would
be written to a file by the <tt class="method">tofile()</tt> method.)
</dl>
<P>
<dl><dt><b><a name='l2h-778'><tt class='method'>write</tt></a></b> (<var>f</var>)
<dd>
<b>Deprecated since release 1.5.1.</b>
Use the <tt class="method">tofile()</tt> method.<p>
Write all items (as machine values) to the file object <var>f</var>.
</dl>
<P>
When an array object is printed or converted to a string, it is
represented as <code>array(<var>typecode</var>, <var>initializer</var>)</code>. The
<var>initializer</var> is omitted if the array is empty, otherwise it is a
string if the <var>typecode</var> is <code>'c'</code>, otherwise it is a list of
numbers. The string is guaranteed to be able to be converted back to
an array with the same type and value using reverse quotes
(<code>``</code>), so long as the <tt class="function">array()</tt> function has been
imported using "<tt class="samp">from array import array</tt>". Examples:
<P>
<dl><dd><pre class="verbatim">
array('l')
array('c', 'hello world')
array('l', [1, 2, 3, 4, 5])
array('d', [1.0, 2.0, 3.14])
</pre></dl>
<P>
<div class='seealso'>
<p class='heading'><b>See Also:</b></p>
<dl compact class="seemodule">
<dt>Module <b><tt class='module'><a href="module-struct.html" tppabs="http://www.python.org/doc/current/lib/module-struct.html">struct</a></tt>:</b>
<dd>packing and unpacking of heterogeneous binary data.
</dl>
<dl compact class="seemodule">
<dt>Module <b><tt class='module'><a href="module-xdrlib.html" tppabs="http://www.python.org/doc/current/lib/module-xdrlib.html">xdrlib</a></tt>:</b>
<dd>packing and unpacking of XDR data.
</dl>
<div class="seetext"><p>The Numeric Python extension (NumPy) defines another array
type; see <i>The Numerical Python Manual</i> for additional
information (available online at
<a class="url" href="javascript:if(confirm('ftp://ftp-icf.llnl.gov/pub/python/numericalpython.pdf \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='ftp://ftp-icf.llnl.gov/pub/python/numericalpython.pdf'" tppabs="ftp://ftp-icf.llnl.gov/pub/python/numericalpython.pdf">ftp://ftp-icf.llnl.gov/pub/python/numericalpython.pdf <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
></a>).
Further information about NumPy is available at
<a class="url" href="javascript:if(confirm('http://www.python.org/topics/scicomp/numpy.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.python.org/topics/scicomp/numpy.html'" tppabs="http://www.python.org/topics/scicomp/numpy.html">http://www.python.org/topics/scicomp/numpy.html <img src="offsite.gif" tppabs="http://www.python.org/doc/current/icons/offsite.gif"
border='0' class='offsitelink' height='15' width='17' alt='[off-site link]'
></a>.</div>
</div>
<DIV CLASS="navigation"><p><hr><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>
</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 + -