Search code examples
pythonlogic

Why doesn't the "and" condition work in my Python codes?


Each separate statement is true, but why is the combination of the two with "and" false? codes


Solution

  • In python and is a logical AND that returns True if both the operands are true whereas ‘&’ is a bitwise operator. I think you are trying to to something like this.

    if (other_list[0] == 0 and rand_vec[0] == 1):
        # Do something