On 8 October 2012 21:26, Barry Warsaw <span dir="ltr"><<a href="mailto:barry@python.org" target="_blank">barry@python.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Oct 08, 2012, at 03:44 PM, Mike Graham wrote:<br>
<br>
>I regularly see learners using "is" to check for string equality and<br>
>sometimes other equality. Due to optimizations, they often come away<br>
>thinking it worked for them.<br>
><br>
>There are no cases where<br>
><br>
> if x is "foo":<br>
><br>
>or<br>
><br>
> if x is 4:<br>
><br>
>is actually the code someone intended to write.<br>
><br>
>Although this has no benefit to anyone but new learners, it also<br>
>doesn't really do any harm.<br>
<br>
</div>Conversely, I often see this:<br>
<br>
if x == None<br>
<br>
and even<br>
<br>
if x == True<br>
<br>
Okay, so maybe these are less harmful than the original complaint, but still,<br>
yuck!<br></blockquote></div><br><div>We can't really warn against these.</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<font face="courier new, monospace">>>> class EqualToTrue:<br>... def __eq__(self, other):<br>... return other is True<br>... <br>>>> EqualToTrue() is True<br>False<br>>>> EqualToTrue() == True<br>
True</font></blockquote></div>