<div>On Wed, Mar 30, 2011 at 11:31 AM, Edward Cherlin <span dir="ltr">&lt;<a href="mailto:echerlin@gmail.com">echerlin@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex; ">
So &#39;in&#39; is a comparison &quot;operator&quot;, is it? I am annoyed at how long it<br>took me to verify that Python treats it as such, and I am also annoyed<br>that it is so.<br><br><a href="http://docs.python.org/tutorial/datastructures.html" target="_blank">http://docs.python.org/tutorial/datastructures.html</a><br>
5.7. More on Conditions¶<br><br>The conditions used in while and if statements can contain any<br>operators, not just comparisons.<br></blockquote><div> </div></div>As you no doubt know, in triggers the rib __contains__ in the cosmic <div>
backbone of Python&#39;s special names list, whereas operators like ==,</div><div>&gt; and &lt; trigger their own specially named reflexes:<div><div><br></div><div><div>&gt;&gt;&gt; class Foo:</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>def __contains__(self, value):</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>print (&quot;Yes {} is in the bar&quot;.format(value))</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>return True</div><div><br></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>&gt;&gt;&gt; bar = Foo()</div><div>&gt;&gt;&gt; &quot;Joe&quot; in bar</div><div>Yes Joe is in the bar</div><div>True</div><div><br></div><div><br>
</div><div>&gt;&gt;&gt; class Average:</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>def __lt__(self, value):</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>print(&quot;Yes {} is better than Average&quot;.format(value))</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>return True</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>&gt;&gt;&gt; bar = Average()</div><div>&gt;&gt;&gt; &quot;Joe&#39;s bar&quot; &gt; bar</div>
<div>Yes Joe&#39;s bar is better than Average</div><div>True</div><div>&gt;&gt;&gt; </div><div><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
The comparison operators in and not in check whether a value occurs<br>
(does not occur) in a sequence.<br>
<br>
I never cared for the misleading a&lt;b&lt;c notation anyway, and won&#39;t use it.<br>
<div><div></div><div class="h5"><br></div></div></blockquote><div><br></div><div>heretic!</div><div><br></div><div>Kirby</div><div><br></div><div><br></div></div></div></div></div>