You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: special-method-names.html
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ <h1>Special Method Names</h1>
18
18
</blockquote>
19
19
<pid=toc>
20
20
<h2id=divingin>Diving In</h2>
21
-
<pclass=f>Throughout this book, you’ve seen examples of “special methods” — certain “magic” methods that Python invokes when you use certain syntax. Using special methods, your classes can act like sequences, like dictionaries, like functions, like iterators, or even like numbers. This appendix serves both as a reference for the special methods we’ve seen already and a brief introduction to some of the more esoteric ones.
21
+
<pclass=f>Throughout this book, you’ve seen examples of “special methods” — certain “magic” methods that Python invokes when you use certain syntax. Using special methods, your classes can act like sets, like dictionaries, like functions, like iterators, or even like numbers. This appendix serves both as a reference for the special methods we’ve seen already and a brief introduction to some of the more esoteric ones.
22
22
23
23
<h2id=basics>Basics</h2>
24
24
@@ -245,9 +245,9 @@ <h2 id=acts-like-function>Classes That Act Like Functions</h2>
245
245
<li>Given the first 12 bytes of a zip file, decrypt them by mapping the bytes to <var>zd</var>, in effect “calling” <var>zd</var> 12 times, which invokes the <code>__call__()</code> method 12 times, which updates its internal state and returns a resulting byte 12 times.
246
246
</ol>
247
247
248
-
<h2id=acts-like-list>Classes That Act Like Sequences</h2>
248
+
<h2id=acts-like-set>Classes That Act Like Sets</h2>
249
249
250
-
<p>If your class acts as a container for a set of values — that is, if it makes sense to ask whether your class “contains” a value — then it should probably define the following special methods that make it act like a sequence.
250
+
<p>If your class acts as a container for a set of values — that is, if it makes sense to ask whether your class “contains” a value — then it should probably define the following special methods that make it act like a set.
251
251
252
252
<table>
253
253
<tr><th>Notes
@@ -264,7 +264,7 @@ <h2 id=acts-like-list>Classes That Act Like Sequences</h2>
<pid=acts-like-list-example>The <ahref=http://docs.python.org/3.1/library/cgi.html><code>cgi</code> module</a> uses these methods in its <code>FieldStorage</code> class, which represents all of the form fields or query parameters submitted to a dynamic web page.
267
+
<pid=acts-like-set-example>The <ahref=http://docs.python.org/3.1/library/cgi.html><code>cgi</code> module</a> uses these methods in its <code>FieldStorage</code> class, which represents all of the form fields or query parameters submitted to a dynamic web page.
268
268
269
269
<preclass=pp><code># A script which responds to http://example.com/search?q=cgi
270
270
import cgi
@@ -319,7 +319,7 @@ <h2 id=acts-like-dict>Classes That Act Like Dictionaries</h2>
<p>The <ahref=#acts-like-list-example><code>FieldStorage</code> class</a> from the <ahref=http://docs.python.org/3.1/library/cgi.html><code>cgi</code> module</a> also defines these special methods, which means you can do things like this:
322
+
<p>The <ahref=#acts-like-set-example><code>FieldStorage</code> class</a> from the <ahref=http://docs.python.org/3.1/library/cgi.html><code>cgi</code> module</a> also defines these special methods, which means you can do things like this:
323
323
324
324
<preclass=pp><code># A script which responds to http://example.com/search?q=cgi
0 commit comments