Three methods of parallel judging python if multiple conditions

Three methods of parallel judging python if multiple conditions

What if you use python's if to judge multiple conditional expressions? Here are three methods:

  1. Use and or or to connect multiple conditional expressions, such as condition 1 and condition 2 and condition 3, etc. When using and to connect multiple expressions, as long as one of the expressions is False, the if condition is False, otherwise it is True, on the contrary, in the expressions connected by or, as long as one expression is True, the if condition is True, otherwise it is False;
  2. The mixed use of and and or, the priority of the two is executed in sequence;
  3. Use comparison operators, such as 1<=x >=2;

if multiple conditions parallel judgment example code

>>> if True and True and False:
...     print("True")
... 
>>> if False or False or True:
...     print("True")
... 
True
>>> if True and False or True:
...     print("True")
... 
True
>>> if True and False or False:
...     print("True")
... 
>>> if 1 < 2 < 3:
...     print("True")
... 
True

Original: Three methods of judging multiple conditions in python if

Guess you like

Origin blog.csdn.net/weixin_47378963/article/details/130551113