# OPERATORS :-
As we all know that the python is very powerful and most commonly used programming language in the whole world.So it provide many powerful operators. operators have the power to apply on the operands and manipulate their values according to the operation applied on them.
In other words Operators are used to perform some specific operations on operands or we can say variables or values. Operators are either represented by keywords or special characters. For example for Identity operator we use keyword "is" and "is not".
EXAMPLE :- Suppose we have an expression 4+5=9
Here 4 and 5 are operators and + is an operator which is applied on the operands to perform the operation of addition.
#TYPES OF OPERATORS :-
Basically python is very rich in operators. Some of the python operators listen below :-
1. Arithmetic Operators
2. Assignment Operators
3. Comparison Operators
4. Logical / Relational Operators
5. Identical Operators
6. Membership Operators
7. Bit-wise Operators
#ARITHMETIC OPERATORS :-
Arithmetic operators are those which are used whit numeric values to perform common mathematical operations.
Suppose a=40 and b=20 then :-
OPERATORS
|
EXAMPLE
|
RESULT
|
+ Addition
|
X+Y
|
60
|
- Subtraction
|
X-Y
|
20
|
* Multiplication
|
X*Y
|
800
|
/ Division
|
X/Y
|
2
|
% Modulus
|
X%Y
|
0
|
** Exponent
|
X**Y
|
40 to the power 20
|
#ASSIGNMENT OPERATORS :-
Assignment operators are used to assign the values to the variables. Some of the Assignment operators are listen below.
Operator symbol
|
Example
|
Explanation
|
=
|
X=5
|
X=5
|
+=
|
X+=5
|
X=x+5
|
-=
|
x-=5
|
X=x-5
|
*=
|
X*=5
|
X=x*5
|
/=
|
x/=5
|
X=x/5
|
%=
|
X%=5
|
X=x%5
|
# COMPARISON OPERATORS :-
The operators which are used to compare the values of two variables are called Comparison Operators. the comparison operators are listen below :-
Operator symbol
|
Name
|
Example
|
==
|
Equal
|
X==Y
|
!=
|
Not
Equal
|
X!=Y
|
>
|
Greater
than
|
X>Y
|
<
|
Less
than
|
X<Y
|
>=
|
Greater
than Equal
|
X>=Y
|
<=
|
Less
than Equal
|
X<=Y
|
#LOGICAL OPERATORS :-
These are the operators which are used to check the condition either it is true or false. Logical AND , logical OR , Logical NOT are the logical or relational operators in python.
CONDITIONS FOR LOGICAL OPERATORS :-
- LOGICAL AND : It returns true only if both the conditions are true.
- LOGICAL OR : It returns true if any of one condition is true.
- LOGICAL NOT : It returns false if condition is true.
For example suppose x=2 then :
OPERATORS
|
PROCESSING
|
RESULT
|
AND
|
x<5
AND
x<10
|
TRUE
|
OR
|
x>5
OR
x<10
|
TRUE
|
NOT
|
x<5
NOT
X<10
|
FALSE
|
#IDENTITY OPERATORS :-
OPERATORS
|
DESCRIPTION
|
EXAMPLE
|
is
|
Returns true if both values are at same location.
|
X is Y
|
is not
|
Returns true if both values are not at same location.
|
X is not Y
|
# MEMBERSHIP OPERATORS :-
OPERATORS
|
DESCRIPTION
|
EXAMPLE
|
In
|
Returns true if both values are present
|
X in Y
|
Not in
|
Returns true if both values are not present
|
X not in Y
|
#BIT-WISE OPERATORS :-
A bit-wise operator is a character representing an action that works on data at the bit level rather than with bytes or large units of data.
Operator
|
Description
|
Example
|
&
Binary AND
|
Operator
copies a bit to the result if it exists in both operands
|
(a
& b) (means 0000 1100)
|
|
Binary OR
|
It
copies a bit if it exists in either operand.
|
(a
| b) = 61 (means 0011 1101)
|
^
Binary XOR
|
It
copies the bit if it is set in one operand but not both.
|
(a
^ b) = 49 (means 0011 0001)
|
~
Binary Ones Complement
|
It
is unary and has the effect of 'flipping' bits.
|
(~a
) = -61 (means 1100 0011 in 2's complement form due to a signed binary
number.
|
<<
Binary Left Shift
|
The
left operands value is moved left by the number of bits specified by the
right operand.
|
a
<< 2 = 240 (means 1111 0000)
|

