Example
In [1]:
2 + 3
Out[1]:
'+ is the operator symbol, 2 and 3 are the operands
In [7]:
x = 15
y = 6
# Addition Operator
print('x + y = ', x + y)
# Subtraction Operator
print('x - y = ', x - y)
# Multiplication Operator
print('x * y = ', x * y)
# Division Operator
print('x / y = ', x / y) # True Division
print('x // y =', x//y) # Class Division
# Exponential Operator
print('x ** y = ', x ** y)
In [11]:
x = 12
y = 10
# Greater Than Operator
print('x > y = ',x > y)
# Greater Than or Equal To
print('x >= y', x >= y)
# Lesser Than Operator
print('x < y = ',x < y)
# Lesser Than or Equal To
print('x <= y', x <= y)
# Equal To Operator
print('x == y ',x == y)
# Not Equal To
print('x != y', x != y)
In [6]:
x = 10
y = 4
# Bitwise AND
print('x & y = ', x & y)
# Bitwise OR
print('x | y = ', x | y)
# Bitwise NOT
print('~ x = ', ~ x)
# Bitwise XOR
print('x ^ y = ', x ^ y)
# Right shift
print('x >> y = ', x >> y)
# Left Shift
print('x << y = ', x << y)
In [12]:
a = 5
print(a)
a += 5 # a = a + 5
print(a)
a -= 5 # a = a - 5
print(a)
a *= 5 # a = a * 5
print(a)
a /= 5 # a = a / 5
print(a)
a //= 2 # a = a // 2
print(a)
a %= 1 # a = a % 1
print(a)
a = 10
a **= 2 # a = a ** 2
print(a)
is - True if the operands are identical is not - True if the operands are not identical
In [16]:
x1 = 2
y1 = 2
x2 = 'Hello'
y2 = "Hello"
x3 = [1,2,3]
y3 = (1,2,3)
print('x1 is y1 = ', x1 is y1)
print('x1 is y2 = ', x1 is y2)
print('x3 is not y3 = ', x3 is not y3)
In [17]:
x = 'Hello World'
y = {1:'a',2:'b'}
print("'H' in x ", 'H' in x)
print('hello not in x ','hello' not in x)
print('1 in y = ',1 in y)
print('a in y = ',a in y)