Logical operators: These operators returns True or False be validating more than one expression
Operator | Meaning | Example |
and | True if both the operands are true | x and y |
or | True if either of the operands is true | x or y |
not | True 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…) |