mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
validation fiddling
This commit is contained in:
+1
-1
@@ -76,7 +76,7 @@ class PapayaWhip: <span>①</span>
|
||||
class Fib:
|
||||
<a> """iterator that yields numbers in the Fibanocci sequence""" <span>①</span></a>
|
||||
|
||||
<a> def __init__(self, max): <span>②</span></code></pre>
|
||||
<a> def __init__(self, max): <span>②</span></a></code></pre>
|
||||
<ol>
|
||||
<li>Classes can (and should) have <code>docstring</code>s too, just like modules and functions.
|
||||
<li>The <code>__init__()</code> method is called immediately after an instance of the class is created. It would be tempting but incorrect to call this the constructor of the class. It’s tempting, because it looks like a constructor (by convention, the <code>__init__()</code> method is the first method defined for the class), acts like one (it’s the first piece of code executed in a newly created instance of the class), and even sounds like one. Incorrect, because the object has already been constructed by the time the <code>__init__()</code> method is called, and you already have a valid reference to the new instance of the class.
|
||||
|
||||
Reference in New Issue
Block a user