Day 5 Python(Operators)
Day 5 Python(Operators)
Returns True if
both the
and x and y x>7 and x>10
operands are
true
Returns True if
or either of the x or y x<7 or x>15
operands is true
Returns True if
not(x>7 and x>
not the operand is not x
10)
false
Truth Table for Logical Operators in Python
a = 10
b = 10
c = -10
else:
print("Atleast one number is not greater than 0")
Python OR Operator
a = 10
b = -10
c=0
if a > 0 or b > 0:
print("Either of the number is greater than 0")
else:
print("No number is greater than 0")
if b > 0 or c > 0:
print("Either of the number is greater than 0")
else:
print("No number is greater than 0")
Python NOT Operator
a = 10
if not a:
print("Boolean value of a is True")
if not (a % 3 == 0 or a % 5 == 0):
print("10 is not divisible by either 3 or 5")
else:
print("10 is divisible by either 3 or 5")
SYNTAX
OPERATOR NAME DESCRIPTION
Result bit 1, if
both operand x
Bitwise AND bits are 1; &
& Bitwise AND
operator otherwise y
results bit 0.
Result bit 1, if
any of the x
Bitwise OR operand bit is 1; |
| Bitwise OR
operator otherwise y
results bit 0.
Result bit 1, if
any of the
Bitwise XOR operand bit is 1 x^
^ Bitwise XOR but not both, y
Operator
otherwise
results bit 0.