Python provides the if
statement in order to check different conditions and run code accordingly. The if statement can be used with the and
logic operator in order to match multiple conditions.
“if and” Syntax
The if and
statement condition is like below.
if CONDTION and CONDITION
- CONDITON is condition which will be evaluated to
True
orFalse
.
“if and” Two Conditions
In the following example, we evaluate two conditions by using the “if and” statement. For the first statement “a and b” is True but for the second statement “a and c” is not True and does not print anything.
a = True
b = True
c = False
if a and b:
print("a and b True")
if a and c:
print("a and c False")
“if and” Multiple Conditions
The “if and” statement can be used for multiple conditions at the same time. In the following example we check if provided a, b and c are True.
a = True
b = True
c = True
if a and b and c:
print("a and b and c returns True")
a = True
b = False
c = True
if a and b and c:
print("a and c False")