24
loading...
This website collects cookies to deliver better user experience
print('Addition(+) :', 10 + 2)
print('Subtraction(-) :', 10 - 7)
print('Multiplication(*) :', 3 * 4)
print('Float Division(/) :', 10 / 3)
print('Floor Division(//) :', 10 // 3)
print('Modulus(%) :', 10 % 3)
print('Exponent(**) :', 3 ** 2)
# Output
# Addition(+) : 12
# Subtraction(-) : 3
# Multiplication(*) : 12
# Float Division(/) : 3.3333333333333335
# Floor Division(//) : 3
# Modulus(%) : 1
# Exponent(**) : 9
# Comparison Operators
print('10 Greater than (>) 5:', 10 > 5)
print('10 Greater than or equal to (>=) 11:', 10 >= 11)
print('20 Less than (<) 19:', 20 < 19)
print('7 Less than or equal to (<=) 9:', 7 <= 9)
print('10 equal to (==) 5:', 10 == 5)
print('5 equal to (==) 5:', 5 == 5)
print('10 not equal to (!=) 5:', 10 != 5)
# Output
# 10 Greater than (>) 5: True
# 10 Greater than or equal to (>=) 11: False
# 20 Less than (<) 19: False
# 7 Less than or equal to (<=) 9: True
# 10 equal to (==) 5: False
# 5 equal to (==) 5: True
# 10 not equal to (!=) 5: True
# Logical Operators
x = True
y = False
print('x and y:', x and y)
print('x or y:', x or y)
print('not x:', not x)
print('not y:', not y)
# Output
# x and y: False
# x or y: True
# not x: False
# not y: True
# Logical Operators with non-boolean operands
x = 4
y = 0
print('x and y:', x and y)
print('x or y:', x or y)
# Output
# x and y: 0
# x or y: 4
# Numeric Value
bool(1)
# Output: True
bool(7)
# Output: True
bool(0)
# Output: False
# String Value
bool('')
# Output: False
bool('Hello World')
# Output: True
print(not 5)
# Output: False
"""
In boolean context 5 is a truthy value so not 5 will give False
"""
print(7 and '')
# Output: ''
"""
In boolean context 7 is truthy value and an empty string is a falsy value so 7 and '' expression will result into ''.
"""
print(5 or 0)
# Output: 5
"""
In boolean context 5 is a truthy value and 0 is a falsy value so 5 or 0 will give 5 as output.
"""
#Assignment Operators
x = 15
x += 5
"""
Output: 20
Because x += 5 is equivalent to x = x + 5
"""
y = 8
y *= 2
"""
Output: 16
Because y *= 2 is equivalent to x = y * 2
"""
# Identity Operators
# Identity Operators
x = 23
y = 23
a = 'Python'
b = 'Python'
t = [1, 2, 3, 4, 5] # list data structure
v = [1, 2, 3, 4, 5] # list data structure
x is y
# Output: True
a is not b
# Output: False
t is v
# Output: False
t is not v
# Output: True
# Membership Operator
a = 'Hello'
b = 'Hello World!'
c = 'Python'
d = 'He'
a in b
# Output: True
c in b
# Output: False
d in b
# Output: True
d not in c
# Output: True