# Arithmetic operators + - * / % ** //
# Assignment operators = += -= *= /= %= //= **= &= |= ^= >>= <<=
# Comparison operators == != > < >= <=
# Logical operators and or not
# Identity operators is is not
# Membership operators in not in
# Bitwise operators & | ^ ~ << >>
# Arithmetic operators + - * / % ** //
x,y = 911,247
print('x=',x)
print('y=',y)
print()
print('x+y=',x+y)
print('x-y=',x-y)
print('x*y=',x*y)
print('x/y=',x/y)
print()
print('3**2=',3**2) #Exponentiation
print()
print('x%y=',x%y) #Modulus
print('x//y=',x//y)# FloorDivision
z = (y * ( x // y) + (x % y))
print(z) # check Modulus + floor division
Output:
x= 911
y= 247
x+y= 1158
x-y= 664
x*y= 225017
x/y= 3.688259109311741
3**2= 9
x%y= 170
x//y= 3
911
# Assignment operators = += -= *= /= %= //= **= &= |= ^= >>= <<=
a = 5
b = 3
print(a,b)
print()
a += b
print('a += b ' ,a)
a -= b
print('a -= b ' ,a)
a *= b
print('a -= 5 ' ,a)
a /= b
print('a /= b ' ,a)
print()
a **= b
print('a **= b ' ,a)
a %= b
print('a %= b ' ,a)
a //= b
print('a //= b ' ,a)
print()
a=5
b=3
a &= b
print('a &= b ' ,a)
a |= b
print('a |= b ' ,a)
a ^= b
print('a ^= b ' ,a)
print()
a=5
b=3
a <<=b
print('a <<= b ' ,a)
a >>=b
print('a >>= b ' ,a)
output
5 3
a += b 8
a -= b 5
a -= 5 15
a /= b 5.0
a **= b 125.0
a %= b 2.0
a //= b 0.0
a &= b 1
a |= b 3
a ^= b 0
a <<= b 40
a >>= b 5
--------------------------------
# Comparison Operators
a = 15
b = 13
print(a,b)
print()
print('a == b ' ,a==b)
print('a != b ' ,a!=b)
print('a > b ' ,a>b)
print('a < b ' ,a<b)
print('a >= b ' ,a>=b)
print('a <= b ' ,a<=b)
print()
output:
15 13
a == b False
a != b True
a > b True
a < b False
a >= b True
a <= b False
-----------------------------
#Logical operators and or not
a=6
print ('a>4 and a <11 ',a>4 and a<11)
print()
print('a>4 or a <11 ', a>4 or a<11)
print()
print('not(a>4 and a <11) ', not(a>4 and a<11))
print()
output:
a>4 and a <11 True
a>4 or a <11 True
not(a>4 and a <11) False
No comments:
Post a Comment