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

📄 109.html

📁 国外python经典教材,python爱好者的首选
💻 HTML
📖 第 1 页 / 共 3 页
字号:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Essential Reference, Second Edition -&gt; Mathematics</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyM.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="2.html" class="navtitle">Linux/Unix</a> &gt; <a href="0735710910.html" class="navtitle">Python Essential Reference, Second Edition</a> &gt; <a href="105.html" class="navtitle">A. The Python Library</a> &gt; <span class="nonavtitle">Mathematics</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="108.html" title="Python Services"><font size="1">&lt;&nbsp;BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0735710910&snode=109" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="109.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="110.html" title="String Handling"><font size="1">CONTINUE&nbsp;&gt;</font></a></td></TR></TABLE>
<a href="5%2F28%2F2002+9%3A05%3A29+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>155117184014003188065099048180054212144238241179195140058238111161105083198025091079203031</font><a href="read5.asp?bookname=0735710910&snode=109&now=5%2F28%2F2002+9%3A05%3A29+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT>
<h3>Mathematics</h3>
<p>The modules in this section provide a variety of mathematical functions.</p>

<A NAMe="2"></a>
<h4><tT CLAss="monofont">array</tt></H4>
<P>The <TT class="monofont">array</tt>  module defines a new object type <tt class="monofont">ArrayType</tt>  that works almost exactly like other sequence types except that its contents are constrained to a single type. The type of an array is determined at the time of creation, using one of the following typecodes:</p>

<p><taBle BordEr="1" celLspaCING="0" cellPADDing="1" wIDTH="100%">
<colgROUP span="4">
<tr>
<th valign="top">
<font siZe="2">
<p><B>Type Code</b></p>
</fOnt></th>
<Th vaLIGN="top">
<font SIZE="2">
<p><b>Description</b></p>
</FONT></th>
<th VALIgn="top">
<font size="2">
<p><b>C Type</b></p>
</font></th>
<Th vAligN="top">
<font Size="2">
<P><B>Minimum Size (in bytes)</B></P>
</font></TH>
</TR>
<tr>
<td VALIgn="top">
<foNT SIze="2">
<p><tt class="monofont">'c'</tt></p>
</font></td>
<tD vaLign="top">
<Font sIze="2">
<p>8-bit character</P>
</FONt></td>
<tD VALign="top">
<fONT Size="2">
<p><TT CLass="monofont">char</tt></p>
</font></td>
<td valign="top">
<FonT sizE="2">
<p>1</p>
</foNt></td>
</TR>
<TR>
<td vaLIGN="top">
<font SIZE="2">
<p><tt cLASS="monofont">'b'</tt></p>
</font></td>
<td valign="top">
<fonT siZe="2">
<p>8-bit integer</p>
</Font></tD>
<td vALIGn="top">
<fonT SIZe="2">
<p><tt CLASs="monofont">signedchar</tt></p>
</FONT></td>
<td valign="top">
<font size="2">
<p>1</p>
</FonT></td>
</tR>
<tr>
<td ValiGN="top">
<FOnt siZE="2">
<P><Tt claSS="monofont">'B'</TT></p>
</fonT></TD>
<Td valign="top">
<font size="2">
<p>8-bit unsigned integer</p>
</fonT></td>
<Td vaLign="top">
<fOnt sIZE="2">
<P><tt clASS="monofont">unsignedchar</Tt></p>
</foNT></TD>
<td vaLIGN="top">
<font size="2">
<p>1</p>
</font></td>
</tr>
<tr>
<Td vAligN="top">
<font Size="2">
<P><TT Class="monofont">'h'</TT></P>
</Font></tD>
<TD ValigN="top">
<FONt size="2">
<p>16-bit integer</p>
</font></td>
<td valigN="top">
<foNt siZe="2">
<p><tt ClasS="monofont">short</TT></P>
</font></TD>
<TD valiGN="top">
<FOnt siZE="2">
<P>2</P>
</font></td>
</tr>
<tr>
<td valign="top">
<foNt sIze="2">
<p><Tt claSs="monofont">'H'</tt></P>
</FONt></td>
<tD VALign="top">
<fONT Size="2">
<p>16-bit unsigned integer</P>
</FONt></td>
<td valign="top">
<font size="2">
<p><Tt cLass="monofont">unsignedshort</Tt></p>
</foNt></td>
<TD VAlign="top">
<FONT size="2">
<P>2</P>
</FOnt></td>
</TR>
<TR>
<td valign="top">
<font size="2">
<p><tt cLasS="monofont">'i'</tt></p>
</Font></tD>
<td vALIGn="top">
<fonT SIZe="2">
<p>integer</p>
</fONT></Td>
<td vALIGn="top">
<font size="2">
<p><tt class="monofont">int</tt></p>
</FonT></td>
<tD valiGn="top">
<foNT SIze="2">
<p>4 or 8</p>
</FONT></td>
</tr>
<TR>
<TD valiGN="top">
<FOnt size="2">
<p><tt class="monofont">'I'</tt></p>
</fonT></td>
<Td vaLign="top">
<fOnt sIZE="2">
<P>unsigned integer</p>
</fonT></TD>
<Td valIGN="top">
<Font sIZE="2">
<P><tt class="monofont">unsigned int</tt></p>
</font></td>
<td vaLigN="top">
<fonT size="2">
<P>4 or 8</p>
</foNT></TD>
</tr>
<tr>
<TD VAlign="top">
<FONT size="2">
<P><TT Class="monofont">'l'</tt></p>
</font></td>
<td valigN="top">
<foNt siZe="2">
<p>long integer</p>
</fOnt></tD>
<TD ValigN="top">
<FONt sizE="2">
<P><TT clasS="monofont">long</TT></P>
</font></td>
<td valign="top">
<font siZe="2">
<p>4 or 8</P>
</fonT></td>
</tr>
<Tr>
<td VALIgn="top">
<foNT SIze="2">
<p><tT CLAss="monofont">'L'</tt></P>
</FONt></td>
<td valign="top">
<font size="2">
<p>unsigned long integer</P>
</foNt></td>
<Td valIgn="top">
<fONT Size="2">
<p><TT CLass="monofont">unsigned long</tT></P>
</FOnt></td>
<TD VAlign="top">
<font size="2">
<p>4 or 8</p>
</font></td>
</Tr>
<tR>
<td vAlign="top">
<Font SIZE="2">
<p><tt cLASS="monofont">'f'</tt></p>
</fONT></Td>
<td vALIGn="top">
<font size="2">
<p>single-precision float</p>
</font></td>
<td vAliGn="top">
<foNt sizE="2">
<p><tt CLASs="monofont">float</tt></p>
</FONT></td>
<td VALIgn="top">
<foNT SIze="2">
<p>4</p>
</font></td>
</tr>
<tr>
<td valiGn="top">
<fOnt sIze="2">
<p><tT claSS="monofont">'d'</TT></p>
</fonT></TD>
<Td valIGN="top">
<Font sIZE="2">
<P>double-precision float</p>
</font></td>
<td valign="top">
<font sIze="2">
<P><tt cLass="monofont">double</tT></p>
</foNT></TD>
<td vaLIGN="top">
<font SIZE="2">
<p>8</p>
</foNT></TD>
</tr>
</colgroup>
</table></p>

<p>The representation of integers and long integers is determined by the machine architecture (they may be 32 or 64 bits).When values stored as <tt cLasS="monofont">'L'</tt> or <tT clasS="monofont">'I'</tt> are returned, they抮e returned as Python long integers.</p>

<P>The module defines the following function:</P>

<PRe>

<b>array(</b><b><I>typecode</I></B> <B>[,</b> <b><i>initializer</i></B><B>])</B> </Pre>

<p>Creates an array of type <i><TT CLass="monofont">typecode</tt></i>
. <i><tt class="monofont">initializer</tt></i>
 is a string or list of values used to initialize values in the array. The following attributes and methods apply to an array object <i><tt ClaSs="monofont">a</tt></I>
:</p>

<p><taBle bORDEr="1" celLSPAcing="0" CELLpaddING="1" Width="100%">
<colgroup span="2">
<tr>
<th ValIgn="top">
<fOnt siZe="2">
<p><b>Item</B></P>
</FOnt></th>
<TH VAlign="top">
<FONT size="2">
<P><B>Description</B></P>
</font></th>
</tr>
<tr>
<td valign="top">
<foNt sIze="2">
<p><I><tt clAss="monofont">a</tT></I>
<TT clasS="monofont">.typecode</TT></P>
</font></TD>
<TD valiGN="top">
<FOnt size="2">
<p>Typecode character used to create the array.</p>
</font></td>
</tr>
<tr>
<td ValIgn="top">
<fOnt siZe="2">
<p><i><TT CLass="monofont">a</tT></I>
<TT clasS="monofont">.itemsize</TT></P>
</font></TD>
<TD valign="top">
<font size="2">
<p>Size of items stored in the array (in bytes).</p>
</font></Td>
</tR>
<tr>
<tD valiGn="top">
<foNT SIze="2">
<p><i><TT CLass="monofont">a</tT></I>
<TT clasS="monofont">.append(</TT><I><tt class="monofont">x</tt></i>
<tt class="monofont">)</tt></p>
</FonT></td>
<tD valiGn="top">
<foNT SIze="2">
<p>Appends <i><TT CLass="monofont">x</tT></I>
 to the end of the array.</P>
</Font></tD>
</TR>
<Tr>
<td valign="top">
<font size="2">
<p><i><tT clAss="monofont">a</tT></i>
<tt cLass="monofont">.buffer_info()</TT></P>
</Font></tD>
<TD ValigN="top">
<FONt sizE="2">
<P>Returns <TT class="monofont">(</tt><i><tt class="monofont">address</tt></i>
<tt ClaSs="monofont">, </tt><I><tt clAss="monofont">length</tT></I>
<TT clasS="monofont">)</TT>, giving the memory location and length of the buffer used to store the array.</P>
</font></TD>
</TR>
<tr>
<td VALIgn="top">
<font size="2">
<p><i><tt class="monofont">a</tT></i>
<tT claSs="monofont">.byteswap()</tt></p>
</Font></TD>
<TD valiGN="top">
<FOnt siZE="2">
<P>Swaps the byte ordering of all items in the array from big-endian to little-endian or vice versa. This is only supported for integer values.</P>
</font></TD>
</TR>
<tr>
<td valign="top">
<font size="2">
<p><i><Tt cLass="monofont">a</Tt></i>
<tt ClasS="monofont">.count(</TT><I><tt clASS="monofont">x</Tt></i>
<tt CLASs="monofont">)</tt></p>
</FONT></td>
<td valign="top">
<font size="2">
<p>Returns the number of occurrences of <i><Tt cLass="monofont">x</Tt></i>
 in <i><tT claSS="monofont">a</TT></i>
.</p>
</foNT></TD>
</tr>
<tr>
<TD VAlign="top">
<FONT size="2">
<p><i><tt class="monofont">a</tt></i>
<tt clAss="monofont">.extend(</Tt><i><tT clasS="monofont">b</tt></i>
<TT CLass="monofont">)</tT></P>
</FOnt></td>
<TD VAlign="top">
<FONT size="2">
<p>Appends array <i><tt class="monofont">b</tt></i>
 to the end of array <i><tt cLasS="monofont">a</tt></i>
.</P>
</font></Td>
</tr>
<TR>
<TD valiGN="top">
<FOnt siZE="2">
<P><I><tt clASS="monofont">a</Tt></i>
<tt class="monofont">.fromfile(</tt><i><tt class="monofont">f</tT></i>
<tT claSs="monofont">, </tt><i><Tt clASS="monofont">n</Tt></i>
<tt CLASs="monofont">)</tt></p>
</FONT></td>
<td VALIgn="top">
<font size="2">
<p>Reads <i><tt class="monofont">n</tT></i>
 items (in binary format) from the file object <i><Tt clAss="monofont">f</tt></I>
 and appends to the end of the array. <i><tt CLASs="monofont"><sup>f</SUP></Tt></i>
 must be a file object. Raises <tt CLASs="monofont">EOFError</tt>  if fewer than <i><TT CLass="monofont">n</tt></i>
 items can be read.</p>
</font></td>
</tr>
<tr>
<td vAliGn="top">
<foNt sizE="2">
<p><i><tT CLAss="monofont">a</tt></I>
<TT Class="monofont">.fromlist(</TT><I><Tt claSS="monofont">list</TT></i>
<tt class="monofont">)</tt></p>
</font></td>
<td vAliGn="top">
<foNt sizE="2">
<p>Appends items from <i><tT CLAss="monofont">list</tt></I>
 to the end of the array.</P>
</FOnt></td>
</TR>
<TR>
<td vaLIGN="top">
<font size="2">
<p><i><tt class="monofont">a</tt></i>
<Tt cLass="monofont">.fromstring(</Tt><i><tt ClasS="monofont">s</TT></I>
<tt clASS="monofont">)</Tt></p>
</foNT></TD>
<td vaLIGN="top">
<font size="2">
<p>Appends items from string <i><tt class="monofont">s</tt></i>
 where <I><tt ClasS="monofont">s</tt></i>
 is interpreted as a string of binary values梥ame as would have been read using <tT claSS="monofont">fromfile()</TT>.</p>
</fonT></TD>
</Tr>
<tr>
<tD VALign="top">
<fONT Size="2">
<p><i><tt class="monofont">a</tt></i>
<tt claSs="monofont">.index(</tT><i><tt Class="monofont">x</Tt></i>
<tT CLAss="monofont">)</tt></P>
</FONt></td>
<tD VALign="top">
<fONT Size="2">
<p>Returns the index of the first occurrence of <i><tt class="monofont">x</tt></i>
 in <i><tt clAss="monofont">a</Tt></i>
. Raises <tT clasS="monofont">ValueError</tt> if not found.</p>
</FONT></td>
</tr>
<TR>
<TD valiGN="top">
<FOnt siZE="2">
<P><I><tt class="monofont">a</tt></i>
<tt class="monofont">.insert(</tt><i><Tt cLass="monofont">i</Tt></i>
<tt ClasS="monofont">, </TT><I><tt clASS="monofont">x</Tt></i>
<tt CLASs="monofont">)</tt></p>
</FONT></td>
<td valign="top">
<font size="2">
<p>Inserts <i><Tt cLass="monofont">x</Tt></i>
 before position <i><tT claSS="monofont">i</TT></i>
.</p>
</foNT></TD>
</tr>
<tr>
<TD VAlign="top">

⌨️ 快捷键说明

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