<div dir="ltr">It's because when the rhs is a string, 'in' tests for a substring rather than simple containment. E.g. "ab" in "abc" gives True. So here 'in' is not a collection membership, it only operates on two strings.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 3, 2018 at 4:34 PM, Ethan Furman <span dir="ltr"><<a href="mailto:ethan@stoneleaf.us" target="_blank">ethan@stoneleaf.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This behavior was recently brought to my attention [1]:<br>
<br>
--> 1 in 'hello'<br>
Traceback (most recent call last):<br>
  File "<stdin>", line 1, in <module><br>
TypeError: 'in <string>' requires string as left operand, not int<br>
<br>
However, in any other collection (set, dict, list, tuple, etc), the answer would be False.<br>
<br>
Does anyone remember the reason why an exception is raised in the string instance instead of returning False?<br>
<br>
--<br>
~Ethan~<br>
<br>
<br>
<br>
[1] <a href="https://bugs.python.org/msg314900" rel="noreferrer" target="_blank">https://bugs.python.org/msg314<wbr>900</a><br>
______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/guido%40python.org" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/options/python-dev/guido%<wbr>40python.org</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>