Logic operators with "in" statement
exarkun at twistedmatrix.com
exarkun at twistedmatrix.com
Mon Nov 16 09:12:27 EST 2009
On 02:02 pm, mr.spoon21 at gmail.com wrote:
>Hi,
>I'm trying to use logical operators (or, and) with the "in" statement,
>but I'm having some problems to understand their behavior.
"and" and "or" have no particular interaction with "in".
>
>In [1]: l = ['3', 'no3', 'b3']
>
>In [2]: '3' in l
>Out[2]: True
>
>In [3]: '3' and '4' in l
>Out[3]: False
>
>In [4]: '3' and 'no3' in l
>Out[4]: True
>
>This seems to work as I expected.
What this actually does is '3' and ('no3' in l). So it might have
produced the result you expected, but it didn't work how you expected.
:)
Jean-Paul
More information about the Python-list
mailing list