mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
added sidebar about special methods
This commit is contained in:
@@ -47,7 +47,7 @@ Classname Legend
|
||||
|
||||
.note = "note/caution/important" = indented block for tips/gotchas/language comparisons
|
||||
.baa = "best available ampersand" = wrapper block for ampersands
|
||||
|
||||
.ots = "on the side" = an aside that is set in normal type (as opposed to a big blue pullquote)
|
||||
|
||||
Acknowledgements & Inspirations
|
||||
|
||||
@@ -283,6 +283,14 @@ aside {
|
||||
-webkit-border-radius: 1em;
|
||||
border-radius: 1em;
|
||||
}
|
||||
aside.ots {
|
||||
font-style: normal;
|
||||
font-size: medium;
|
||||
line-height: 1.75;
|
||||
}
|
||||
aside a {
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
/* previous/next navigation links */
|
||||
|
||||
|
||||
@@ -158,6 +158,10 @@ body{counter-reset:h1 6}
|
||||
|
||||
<p><em>Now</em> you’re ready to learn how to build an iterator. An iterator is just a class that defines an <code>__iter__()</code> method.
|
||||
|
||||
<aside class=ots>
|
||||
All three of these class methods, <code>__init__</code>, <code>__iter__</code>, and <code>__next__</code>, begin and end with a pair of underscore (<code>_</code>) characters. Why is that? There’s nothing magical about it, but it usually indicates that these are “<dfn>special methods</dfn>.” The only thing “special” about special methods is that they aren’t called directly; Python calls them when you use some other syntax on the class or an instance of the class. <a href=special-method-names.html>More about special methods</a>.
|
||||
</aside>
|
||||
|
||||
<p class=d>[<a href=examples/fibonacci2.py>download <code>fibonacci2.py</code></a>]
|
||||
<pre><code class=pp><a>class Fib: <span class=u>①</span></a>
|
||||
<a> def __init__(self, max): <span class=u>②</span></a>
|
||||
|
||||
Reference in New Issue
Block a user