vertopal.com_Operator_In_Python
vertopal.com_Operator_In_Python
a = 9
b = 4
# Addition of numbers
add = a + b
# Subtraction of numbers
sub = a - b
# Multiplication of number
mul = a * b
# Division(float) of number
div1 = a / b
# Division(floor) of number
div2 = a // b
# Power
p = a ** b
# print results
print("Addition of numbers = ",add)
print("Subtraction of numbers = ",sub)
print("Multiplication of numbers = ",mul)
print("Division(float) of numbers = ",div1)
print("Division(floor) of numbers = ",div2)
print("Modulo of numbers = ",mod)
print("Power of number = ",p)
Addition of numbers = 13
Subtraction of numbers = 5
Multiplication of numbers = 36
Division(float) of numbers = 2.25
Division(floor) of numbers = 2
Modulo of numbers = 1
Power of number = 6561
c=[1,2,3]
d=[1,2]
d[0]=c*6
d[1]='abc'
print("value is ",d)
print("value is ",c)
a=2 #input()
b=64 #input()
c=[1,2,3]
d=c*2
print("value is ",(c * 2))
#print("value is ",a//b)
value is [1, 2, 3, 1, 2, 3]
a=1567
b=1567//10
c=1567%10
print("b = ",b," c = ",c)
b1= b//10
c1= b%10
print("b1 = ",b1,"number = ",str(c)+str(c1))
b2= b1//10
c2= b1%10
print(a)
b = 156 c = 7
b1 = 15 number = 76
1567
b2 = 1 number = 7651
# a > b is False
print(a > b)
# a < b is True
print(a < b)
# a == b is False
print(a == b)
# a != b is True
print(a != b)
# a >= b is False
print(a >= b)
# a <= b is True
print(a <= b)
False
True
False
True
False
True
# Addition Assignment
a += 5
print ("a += 5 : ", a)
# Subtraction Assignment
a -= 5
print ("a -= 5 : ", a)
# Multiplication Assignment
a *= 5
print ("a *= 5 : ", a)
# Division Assignment
a //= 5
print ("a //= 5 : ",a)
# Remainder Assignment
a %= 3
print ("a %= 3 : ", a)
# Exponent Assignment
a=10
a **= 2
print ("a **= 2 : ", a)
a += 5 : 15
a -= 5 : 10
a *= 5 : 50
a //= 5 : 10
a %= 3 : 1
a **= 2 : 100
a //= 3 : -34
# Binary AND
c = a & b # 12 = 0000 1100
print ("a & b : ", c)
# Binary OR
c = a | b # 61 = 0011 1101
print ("a | b : ", c)
# Binary XOR
c = a ^ b # 49 = 0011 0001
print ("a ^ b : ", c)
a & b : 12
a | b : 61
a ^ b : 49
~a : -61
a << 2 : 240
a >> 2 : 15
# Print a or b is True
print(a or b)
if ( a in list ):
print ("Line 1 - a is available in the given list")
else:
print ("Line 1 - a is not available in the given list")
if ( b not in list ):
print ("Line 2 - b is not available in the given list")
else:
print ("Line 2 - b is available in the given list")
a = 2
if ( a in list ):
print ("Line 3 - a is available in the given list")
else:
print ("Line 3 - a is not available in the given list")
a = '1'
b = 'csmss college of poly'
list1= {1: 2, 3: 4, 5:6 };
print(a in list1)
False
if (x not in list):
print("x is NOT present in given list")
else:
print("x is present in given list")
if (y in list):
print("y is present in given list")
else:
print("y is NOT present in given list")
print(a is not b)
print(a is c)
if ( a is b ):
print ("Line 1 - a and b have same identity")
else:
print ("Line 1 - a and b do not have same identity")
if ( id(a) == id(b) ):
print ("Line 2 - a and b have same identity")
else:
print ("Line 2 - a and b do not have same identity")
b = 30
if ( a is b ):
print ("Line 3 - a and b have same identity")
else:
print ("Line 3 - a and b do not have same identity")
if ( a is not b ):
print ("Line 4 - a and b do not have same identity")
else:
print ("Line 4 - a and b have same identity")
a=10
b=10
#b=a
c=20
print(id(a))
print(id(b))
print(id(c))
print((a))
print((b))
print(a is not b)
100
a,b=100,20
print( (b, a) [a < b] )
20
print ("Both a and b are equal" if a == b else "a is greater than b"
if a > b else "b is greater than a")
e = ((a + b) * c) / d # (30 * 15 ) / 5
print ("Value of ((a + b) * c) / d is ", e)
e = a + (b * c) / d; # 20 + (150/5)
print("Value of a + (b * c) / d is ", e)