python operator
python operator
+ Addition 10 + 20
Subtraction 20- 10
Multiplication 10 * 20 =200
Division 20/ 10 =
% Modulus 22% 10
**
Exponent 4**2 = 16
Example
Following is an example which shows all the
above operations:
a = 21 Edit &Run
b = 10
# Addit ion
print ("a + b : + b
# Subtraction
print ("a - b b
# Floor Division
print ("a // b: a // b
a + b : 31
a - b: 11
a * b: 210
a / b: 2.1
a %b : 1
a ** b : 16679880978201
a // b : 2
ADVERTISEMENT
ADVERTISEMENT
# Addit ion
print ("a + b : ,a + b
# Subtraction
print ("a - b a b
# Mult iplication
print ("a * b * b)
# Division
print ("a / b: " , a / b)
# Modulus
print ("a % b : ", a % b)
# Exponent
print ("a ** b : . a** b)
# Floor Division
print ("a // b: a // b)
a = 4 Edit & Run
b= 5
# Equal
print ("a == b : " .. a == b)
# Not Equal
print ("a != b : a !: b
# Greater Than
print ("a > b: , a > b)
# Less Than
print ("a < b:" a < b)
a == b : False
a != b : True
a > b: False
a <b: True
a >= b : False
a <= b : True
9:57 AMO
X Python -Operators | T.
tutorialspoint.com
Example
Following is an example which shows all the
above comparison operations:
a =4 Edit &Run :
b = 5
# Greater Than or Equal to
a == b :
False
a != b : True
a > b : False
a <b : True
a >= b : False
a <= b : True
ADVERTISEMENT
ADVERTISEMENT
# Addition Assignment
a += 5
print ("a + = 5:
# Subtraction Assignment
a -= 5
print ("a -= 5 a
print ("a *= 5 : a
# Division Assignment
a /- 5
# Remainder Assignment
a %= 3
print ('a %= 3 : a
# Exponent Assignment
a #*= 2
# Floor Division
Assignment
a //= 3
Assignment operators
11
is is not
ldentity operators
12
in not in
Membership operators
13
not or and
Logical operators
Advertisements
Euit pepe
in Evaluates to true if it
x in y, here in
finds a variable in
results in a 1 if
the specified X is a member
sequence and false
of sequence y.
otherwise.
ADVERTISEMENT
9:58 AMO
3
*/%/
6
&
Bitwise 'AND'
Comparison operators
9
<>= =
Equality operators
10
=%= |== + = *= **=
Assignment operators
Operator Description Exam
Python Membership
Operators
Python's membership operators test for
membership in a sequence, such as strings, lists,
or tuples. There are two membership operators
as explained below -
1
3
*/% I/
>><<
[Show xample ]
Sr.No. Operator &Description
+= Addition a += 5 (Same
Assignment as a =a + 5)
*=
Multiplication a*=5 (Same
Assignment as a = a *5)
%= Remainder a %= 5 (Same
Assignment as a = a % 5)
Exponent a t**=2(Same
Assignment as a = a ** 2)
Example
Following is an example which shows all