Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5565d9c

Browse files
author
Mark Pilgrim
committed
explain any()
1 parent 7407a41 commit 5565d9c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

special-method-names.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ <h2 id=acts-like-set>Classes That Act Like Sets</h2>
286286
<a> return len(self.keys()) <span class=u>&#x2464;</span></a></code></pre>
287287
<ol>
288288
<li>Once you create an instance of the <code>cgi.FieldStorage</code> class, you can use the &#8220;<code>in</code>&#8221; operator to check whether a particular parameter was included in the query string.
289-
<li>The <code>__contains__()</code> method is the magic that makes this work.
290-
<li>When you say <code>if 'q' in fs</code>, Python looks for the <code>__contains__()</code> method on the <var>fs</var> object, which is defined in <code>cgi.py</code>. The value <code>'q'</code> is passed into the <code>__contains__()</code> method as the <var>key</var> argument.
289+
<li>The <code>__contains__()</code> method is the magic that makes this work. When you say <code>if 'q' in fs</code>, Python looks for the <code>__contains__()</code> method on the <var>fs</var> object, which is defined in <code>cgi.py</code>. The value <code>'q'</code> is passed into the <code>__contains__()</code> method as the <var>key</var> argument.
290+
<li>The <code>any()</code> function takes a <a href=advanced-iterators.html#generator-expressions>generator expression</a> and returns <code>True</code> if the generator spits out any items. The <code>any()</code> function is smart enough to stop as soon as the first match is found.
291291
<li>The same <code>FieldStorage</code> class also supports returning its length, so you can say <code>len(<var>fs</var>)</code> and it will call the <code>__len__()</code> method on the <code>FieldStorage</code> class to return the number of query parameters that it identified.
292292
<li>The <code>self.keys()</code> method checks whether <code>self.list is None</code>, so the <code>__len__</code> method doesn&#8217;t need to duplicate this error checking.
293293
</ol>

0 commit comments

Comments
 (0)