Python – Logical Operators

Logical operators: These operators returns True or False be validating more than one expression

OperatorMeaningExample
andTrue if both the operands are truex and y
orTrue if either of the operands is truex or y
notTrue if operand is false (complements the operand)not x
And examples:Or examples:Not examples:
>>> True and True
True
>>> 5>3 and 3>2
True
>>> True and False
False
>>> False and True
False
>>> False and False
False
>>> 5>3 and 5!=5
False
>>> False or False
False
>>> False or True
True
>>> True or False
True
>>> True or True
True
>>> 3>5 or 5>2
True
>>> not True
False
>>> not False
True
>>> not 5>3
False
>>> not 3!=3
True  
Check the Number Divisible by 3
N%3==0         (3, 6, 9, 12….)
 
Check the Number Divisible by 5
N%5==0         (5, 10, 15, 20….)
 
Check the Number Divisible by both 3 and 5
N%3==0 and N%5==0           (15, 30, 45, 60….)
 
Check the Number Divisible by either 3 or 5
N%3==0 and N%5==0           (3, 5, 6, 9, 10, 12, 15…)
Scroll to Top