Boolean Operator Confusion

Ian Kelly ian.g.kelly at gmail.com
Fri Apr 24 11:00:13 EDT 2015


On Fri, Apr 24, 2015 at 8:50 AM,  <subhabrata.banerji at gmail.com> wrote:
> Dear Group,
>
> I am trying to understand the use of Boolean operator in Python. I am trying to
> write small piece of script, as follows,
>
> def input_test():
>         str1=raw_input("PRINT QUERY:")
>         if "AND" or "OR" or "NOT" in str1:

This is equivalent to:

    if ("AND") or ("OR") or ("NOT" in str1):

Which is always true because the truth value of the literal strings
"AND" and "OR" are true.

It is not equivalent to:

    if ("AND" in str1) or ("OR" in str1) or ("NOT" in str1):



More information about the Python-list mailing list