Operators in python are constructs in Python that instruct the interpreter
to perform a certain function; however, these are traditionally not defined
as functions; rather, they are syntactically and semantically different from
functions. Operators are used to performing operations on variables and
values according to their use.
Python language supports the following types of operators.
1. Arithmetic Operators
2. Bitwise Operators
3. Membership Operators
4. Identity Operators
5. Comparison Operators
6. Assignment Operators
7. Logical Operators
1. Arithmetic Operator
Arithmetic operators are used to performing mathematical operations
Operator Description Syntax Output
+ Addition a+b Returns sum of the operands
– Subtraction a-b Returns Difference of the operands
/ Division a/b Returns Quotient of the operands
* Multiplication a*b Returns product of the operands
** Exponentiation a**b returns exponent of a raised to the
power b
% Modulus a%b returns remainder of the division
// Floor division a//b returns a real value and ignores the
decimal part
, Let us consider an example program for carrying out the arithmetic
operations explained above.
Xa = int(input('Enter First number: '))
Xb = int(input('Enter Second number: '))
add = Xa + Xb
diff = Xa - Xb
mul = Xa * Xb
div = Xa / Xb
floor_div = Xa // Xb
power = Xa ** Xb
modulus = Xa % Xb
print('Sum of the numbers is',Xa ,'and' ,Xb ,'is :',add)
print('Difference of the numbers is ',Xa ,'and' ,Xb
,'is :',diff)
print('Product of the numbers is ' ,Xa ,'and' ,Xb ,'is :',mul)
print('Division of the numbers is ',Xa ,'and' ,Xb ,'is :',div)
print('Floor Division of the numbers is ',Xa ,'and' ,Xb
,'is :',floor_div)
print('Exponent of the numbers is ',Xa ,'and' ,Xb
,'is :',power)
print('Modulus of the numbers is ',Xa ,'and' ,Xb
,'is :',modulus)
2. Bitwise Operators
Refers to the operators working on a bit, i.e. they treat the operand as a
string of bits; for example, in bitwise operations, 5 will be considered as
0101.
The box below provides the bitwise operators in python