Skip to main content

PYTHON OPERATORS

O
PERATORS


x = 27
y = 3
Python Assignment Operators
print(x + y)
30
print(x - y)
24
print(x * y)
81
print(x / y)
9.0
print(x % y)
0
print(x ** y)
19683
print(x // y)
9
Python Arithmetic Operators
x = 5
x <<= 3
print(x)
40
x >>= 2
print(x)
10
x |= 3
print(x)
11
x &= 3
print(x)
3
x **= 3
print(x)
27
x //= 3
print(x)
9
x %= 3
print(x)
0
x /= 3
print(x)
0.0
x *= 3
print(x)
0.0
x -= 3
print(x)
-3.0
x += 3
print(x)
0.0
x = 5
print(x)
5
Python Comparison Operators
x = 5
y = 3
print(x == y)
False
print(x != y)
True
print(x > y)
True
print(x < y)
False
print(x >= y)
True
print(x = y)
False
Python Logical Operators
x = 5
print(x > 3 and x < 10)
True
print(x < 5 or x < 4)
False
print(not(x < 5 and x < 10))
True
Python Identity Operator
x = ["apple", "banana"]
y = ["Apple", "banana"]
z = x print(x is z)
True
print(x is not y)
True
print(x == y)
False
Python Membership Operators
x = ["apple", "banana"]
print("banana" in x)
True
print("Banana" not in x)
True

Comments