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

📄 node17.html

📁 适合python初学者,一本很好的python学习书籍
💻 HTML
📖 第 1 页 / 共 2 页
字号:
important role in places where a constant hash value is needed.  Forexample as a key in a dictionary.<P><a id='l2h-70' xml:id='l2h-70'></a></DD><DT><STRONG>integer division</STRONG></DT><DD>Mathematical division discarding any remainder.  For example, theexpression <code>11/4</code> currently evaluates to <code>2</code> in contrastto the <code>2.75</code> returned by float division.  Also called<em>floor division</em>.  When dividing two integers the outcome willalways be another integer (having the floor function applied to it).However, if one of the operands is another numeric type (such as a<tt class="class">float</tt>), the result will be coerced (see <em>coercion</em>) toa common type.  For example, an integer divided by a float will resultin a float value, possibly with a decimal fraction.  Integer divisioncan be forced by using the <code>//</code> operator instead of the <code>/</code>operator.  See also <em>__future__</em>.<P><a id='l2h-71' xml:id='l2h-71'></a></DD><DT><STRONG>interactive</STRONG></DT><DD>Python has an interactive interpreter which means that you can try outthings and directly see its result.  Just launch <code>python</code> with noarguments (possibly by selecting it from your computer's main menu).It is a very powerful way to test out new ideas or inspect modules andpackages (remember <code>help(x)</code>).<P><a id='l2h-72' xml:id='l2h-72'></a></DD><DT><STRONG>interpreted</STRONG></DT><DD>Python is an interpreted language, as opposed to a compiled one.  This meansthat the source files can be run directly without first creating anexecutable which is then run.  Interpreted languages typically have ashorter development/debug cycle than compiled ones, though their programsgenerally also run more slowly.  See also <em>interactive</em>.<P><a id='l2h-73' xml:id='l2h-73'></a></DD><DT><STRONG>iterable</STRONG></DT><DD>A container object capable of returning its members one at a time.Examples of iterables include all sequence types (such as <tt class="class">list</tt>,<tt class="class">str</tt>, and <tt class="class">tuple</tt>) and some non-sequence types like<tt class="class">dict</tt> and <tt class="class">file</tt> and objects of any classes you definewith an <tt class="method">__iter__()</tt> or <tt class="method">__getitem__()</tt> method.  Iterablescan be used in a <tt class="keyword">for</tt> loop and in many other places where asequence is needed (<tt class="function">zip()</tt>, <tt class="function">map()</tt>, ...).  When aniterable object is passed as an argument to the builtin function<tt class="function">iter()</tt>, it returns an iterator for the object.  Thisiterator is good for one pass over the set of values.  When usingiterables, it is usually not necessary to call <tt class="function">iter()</tt> ordeal with iterator objects yourself.  The <code>for</code> statement doesthat automatically for you, creating a temporary unnamed variable tohold the iterator for the duration of the loop.  See also<em>iterator</em>, <em>sequence</em>, and <em>generator</em>.<P><a id='l2h-74' xml:id='l2h-74'></a></DD><DT><STRONG>iterator</STRONG></DT><DD>An object representing a stream of data.  Repeated calls to theiterator's <tt class="method">next()</tt> method return successive items in thestream.  When no more data is available a <tt class="exception">StopIteration</tt>exception is raised instead.  At this point, the iterator object isexhausted and any further calls to its <tt class="method">next()</tt> method justraise <tt class="exception">StopIteration</tt> again.  Iterators are required to havean <tt class="method">__iter__()</tt> method that returns the iterator objectitself so every iterator is also iterable and may be used in mostplaces where other iterables are accepted.  One notable exception iscode that attempts multiple iteration passes.  A container object(such as a <tt class="class">list</tt>) produces a fresh new iterator each time youpass it to the <tt class="function">iter()</tt> function or use it in a<tt class="keyword">for</tt> loop.  Attempting this with an iterator will justreturn the same exhausted iterator object from the second iterationpass, making it appear like an empty container.<P><a id='l2h-75' xml:id='l2h-75'></a></DD><DT><STRONG>list comprehension</STRONG></DT><DD>A compact way to process all or a subset of elements in a sequence andreturn a list with the results.  <code>result = ["0x%02x"% x for x in range(256) if x % 2 == 0]</code> generates a list of stringscontaining hex numbers (0x..) that are even and in the range from 0 to 255.The <tt class="keyword">if</tt> clause is optional.  If omitted, all elements in<code>range(256)</code> are processed in that case.<P><a id='l2h-76' xml:id='l2h-76'></a></DD><DT><STRONG>mapping</STRONG></DT><DD>A container object (such as <tt class="class">dict</tt>) that supports arbitrary keylookups using the special method <tt class="method">__getitem__()</tt>.<P><a id='l2h-77' xml:id='l2h-77'></a></DD><DT><STRONG>metaclass</STRONG></DT><DD>The class of a class.  Class definitions create a class name, a classdictionary, and a list of base classes.  The metaclass is responsiblefor taking those three arguments and creating the class.  Most objectoriented programming languages provide a default implementation.  Whatmakes Python special is that it is possible to create custommetaclasses.  Most users never need this tool, but when the needarises, metaclasses can provide powerful, elegant solutions.  Theyhave been used for logging attribute access, adding thread-safety,tracking object creation, implementing singletons, and many othertasks.<P><a id='l2h-78' xml:id='l2h-78'></a></DD><DT><STRONG>LBYL</STRONG></DT><DD>Look before you leap.  This coding style explicitly tests forpre-conditions before making calls or lookups.  This style contrastswith the <em>EAFP</em> approach and is characterized the presence ofmany <tt class="keyword">if</tt> statements.<P><a id='l2h-79' xml:id='l2h-79'></a></DD><DT><STRONG>mutable</STRONG></DT><DD>Mutable objects can change their value but keep their <tt class="function">id()</tt>.See also <em>immutable</em>.<P><a id='l2h-80' xml:id='l2h-80'></a></DD><DT><STRONG>namespace</STRONG></DT><DD>The place where a variable is stored.  Namespaces are implemented asdictionary.  There is the local, global and builtins namespace and thenested namespaces in objects (in methods).  Namespaces supportmodularity by preventing naming conflicts.  For instance, thefunctions <tt class="function">__builtin__.open()</tt> and <tt class="function">os.open()</tt> aredistinguished by their namespaces.  Namespaces also aid readabilityand maintainability by making it clear which modules implement afunction.  For instance, writing <tt class="function">random.seed()</tt> or<tt class="function">itertools.izip()</tt> makes it clear that those functions areimplemented by the <a class="ulink" href="../lib/module-random.html"  ><tt class="module">random</tt></a>and <a class="ulink" href="../lib/module-itertools.html"  ><tt class="module">itertools</tt></a> modulesrespectively.<P><a id='l2h-81' xml:id='l2h-81'></a></DD><DT><STRONG>nested scope</STRONG></DT><DD>The ability to refer to a variable in an enclosing definition.  Forinstance, a function defined inside another function can refer tovariables in the outer function.  Note that nested scopes work onlyfor reference and not for assignment which will always write to theinnermost scope.  In contrast, local variables both read and write inthe innermost scope.  Likewise, global variables read and write to theglobal namespace.<P><a id='l2h-82' xml:id='l2h-82'></a></DD><DT><STRONG>new-style class</STRONG></DT><DD>Any class that inherits from <tt class="class">object</tt>.  This includes allbuilt-in types like <tt class="class">list</tt> and <tt class="class">dict</tt>.  Only new-styleclasses can use Python's newer, versatile features like<tt class="method">__slots__</tt>, descriptors, properties,<tt class="method">__getattribute__()</tt>, class methods, and static methods.<P><a id='l2h-83' xml:id='l2h-83'></a></DD><DT><STRONG>Python3000</STRONG></DT><DD>A mythical python release, allowed not to be backward compatible, withtelepathic interface.<P><a id='l2h-84' xml:id='l2h-84'></a></DD><DT><STRONG>__slots__</STRONG></DT><DD>A declaration inside a <em>new-style class</em> that saves memory bypre-declaring space for instance attributes and eliminating instancedictionaries.  Though popular, the technique is somewhat tricky to getright and is best reserved for rare cases where there are largenumbers of instances in a memory critical application.<P><a id='l2h-85' xml:id='l2h-85'></a></DD><DT><STRONG>sequence</STRONG></DT><DD>An <em>iterable</em> which supports efficient element access usinginteger indices via the <tt class="method">__getitem__()</tt> and<tt class="method">__len__()</tt> special methods.  Some built-in sequence typesare <tt class="class">list</tt>, <tt class="class">str</tt>, <tt class="class">tuple</tt>, and <tt class="class">unicode</tt>.Note that <tt class="class">dict</tt> also supports <tt class="method">__getitem__()</tt> and<tt class="method">__len__()</tt>, but is considered a mapping rather than asequence because the lookups use arbitrary <em>immutable</em> keysrather than integers.<P><a id='l2h-86' xml:id='l2h-86'></a></DD><DT><STRONG>Zen of Python</STRONG></DT><DD>Listing of Python design principles and philosophies that are helpfulin understanding and using the language.  The listing can be found bytyping ``<code>import this</code>'' at the interactive prompt.<P></DD></DL><P><IMG ALIGN="BOTTOM" BORDER="0" SRC="img3.png" ALT="ALT="""><P><DIV CLASS="navigation"><div class='online-navigation'><p></p><hr /><table align="center" width="100%" cellpadding="0" cellspacing="2"><tr><td class='online-navigation'><a rel="prev" title="C. History and License"  href="node16.html"><img src='../icons/previous.png'  border='0' height='32'  alt='Previous Page' width='32' /></A></td><td class='online-navigation'><a rel="parent" title="Python Tutorial"  href="tut.html"><img src='../icons/up.png'  border='0' height='32'  alt='Up One Level' width='32' /></A></td><td class='online-navigation'><a rel="next" title="About this document ..."  href="node18.html"><img src='../icons/next.png'  border='0' height='32'  alt='Next Page' width='32' /></A></td><td align="center" width="100%" class='online-navigation'>Python Tutorial</td><td class='online-navigation'><a rel="contents" title="Table of Contents"  href="node2.html"><img src='../icons/contents.png'  border='0' height='32'  alt='Contents' width='32' /></A></td><td class='online-navigation'><img src='../icons/blank.png'  border='0' height='32'  alt='' width='32' /></td><td class='online-navigation'><img src='../icons/blank.png'  border='0' height='32'  alt='' width='32' /></td></tr></table><div class='online-navigation'><b class="navlabel">Previous:</b><a class="sectref" rel="prev" href="node16.html">C. History and License</A><b class="navlabel">Up:</b><a class="sectref" rel="parent" href="tut.html">Python Tutorial</A><b class="navlabel">Next:</b><a class="sectref" rel="next" href="node18.html">About this document ...</A></div></div><hr /></DIV><!--End of Navigation Panel--><ADDRESS>译者:刘鑫(march.liu AT gmail DOT com) 由:limodou转(limodou AT gmail DOT com)<br>See <i><a href="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 + -