keyword 'in' not returning a bool?

Sion Arrowsmith siona at chiark.greenend.org.uk
Fri Feb 8 13:02:37 EST 2008


In article <mailman.521.1202490602.9267.python-list at python.org>,
c james  <cjames at callone.net> wrote:
>>>> sample = {'t':True, 'f':False}
>>>> 't' in sample == True
>False
>
>Why is this?

http://docs.python.org/lib/comparisons.html

"Comparisons can be chained arbitrarily; for example, x < y <= z is
equivalent to x < y and y <= z, except that y is evaluated only once
[ ... ]
Two more operations with the same syntactic priority, "in" and "not
in", are supported only by sequence types"

So:
't' in sample == True
is equivalent to:
't' in sample and sample == True
and obviously:
>>> sample == True
False

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
        -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list