The operations being carried out on data, are represented by operators. The symbol that trigger the operations on data are called operators.
Types of operators in python:-
- Arithmetic operator
- Assignment Operator
- Comparison operator
- Logical operators
- Membership operators
- Identity operators
- Bitwise operator
1)Arithmetic operator- It is used to perform arithmetic operations between variables.
+ | Addition | a+b |
– | Subtraction | a-b |
* | Multiplication | a*b |
/ | Division | a/b |
% | Modulus | a%b |
** | Exponential | a**b |
// | Floor Division | a//b |
2) Assignment operators- It is used to assign values to variable.
= | 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 |
%= | 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 |
>>= | x>>=5 | x=x>>5 |
<<= | x<<=5 | x=x<<5 |
3) Comparison operator- These operators are used to compare two variables.
== | equals to | x==y |
!= | not equal to | x!=y |
> | Greater than | x>y |
< | Less than | x<y |
>= | Greater than or equal to | x>=y |
<= | Less than or equal to | x<=y |
4) Logical operators- These operators are used to combine conditional statements.
and | returns true if both statements are true |
or | Returns true if one of the statement is true |
not | Returns false if the result is true |
5) Identity operators- Identity operators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location.
is | Returns True if both variables are the same object | x is y |
is not | Returns True if both variables are not the same object | x is not y |
6) Membership operator- Membership operators are used to check if a sequence is present in an object.
in | Returns True if a sequence with the specified value is present in the object | x in y |
not in | Returns True if a sequence with the specified value is not present in the object | x not in y |
7) Bitwise operator- Bitwise operators are used to compare binary numbers.
& | AND | Sets each bit to 1 if both bits are 1 |
| | OR | Sets each bit to 1 if one of two bits is 1 |
^ | XOR | Sets each bit to 1 if only one of two bits is 1 |
~ | NOT | Invert all the bits. |
<< | Shift left by pushing zeros in from the right and let the leftmost bits fall of | |
>> | Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off |
This is all about operators in python.