mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
you wouldn't believe me if I told you
This commit is contained in:
+5
-5
@@ -26,7 +26,7 @@ body{counter-reset:h1 6}
|
||||
|
||||
<p class=d>[<a href=examples/fibonacci2.py>download <code>fibonacci2.py</code></a>]
|
||||
<pre><code>class Fib:
|
||||
"""iterator that yields numbers in the Fibonacci sequence"""
|
||||
'''iterator that yields numbers in the Fibonacci sequence'''
|
||||
|
||||
def __init__(self, max):
|
||||
self.max = max
|
||||
@@ -67,7 +67,7 @@ class PapayaWhip: <span>①</span>
|
||||
|
||||
<p>This <code>PapayaWhip</code> class doesn’t define any methods or attributes, but syntactically, there needs to be something in the definition, thus the <code>pass</code> statement. This is a Python reserved word that just means “move along, nothing to see here”. It’s a statement that does nothing, and it’s a good placeholder when you’re stubbing out functions or classes.
|
||||
|
||||
<blockquote class="note compare java">
|
||||
<blockquote class='note compare java'>
|
||||
<p><span>☞</span>The <code>pass</code> statement in Python is like a empty set of curly braces (<code>{}</code>) in Java or C.
|
||||
</blockquote>
|
||||
|
||||
@@ -79,7 +79,7 @@ class PapayaWhip: <span>①</span>
|
||||
|
||||
<pre><code>
|
||||
class Fib:
|
||||
<a> """iterator that yields numbers in the Fibonacci sequence""" <span>①</span></a>
|
||||
<a> '''iterator that yields numbers in the Fibonacci sequence''' <span>①</span></a>
|
||||
|
||||
<a> def __init__(self, max): <span>②</span></a></code></pre>
|
||||
<ol>
|
||||
@@ -112,7 +112,7 @@ class Fib:
|
||||
<li>You can access the instance’s <code>docstring</code> just as with a function or a module. All instances of a class share the same <code>docstring</code>.
|
||||
</ol>
|
||||
|
||||
<blockquote class="note compare java">
|
||||
<blockquote class='note compare java'>
|
||||
<p><span>☞</span>In Python, simply call a class as if it were a function to create a new instance of the class. There is no explicit <code>new</code> operator like <abbr>C++</abbr> or Java.
|
||||
</blockquote>
|
||||
|
||||
@@ -374,7 +374,7 @@ rules = LazyRules()</code></pre>
|
||||
<li><a href=http://www.python.org/dev/peps/pep-0255/>PEP 255: Simple Generators</a>
|
||||
</ul>
|
||||
|
||||
<p class=nav><a rel=prev href=generators.html title="back to “Generators”"><span>☜</span></a> <a rel=next href=advanced-iterators.html title="onward to “Advanced Iterators”"><span>☞</span></a>
|
||||
<p class=v><a href=generators.html rel=prev title='back to “Generators”'><span>☜</span></a> <a href=advanced-iterators.html rel=next title='onward to “Advanced Iterators”'><span>☞</span></a>
|
||||
|
||||
<p class=c>© 2001–9 <a href=about.html>Mark Pilgrim</a>
|
||||
<script src=j/jquery.js></script>
|
||||
|
||||
Reference in New Issue
Block a user