Operators are used to perform operations on variables and values.
Python divides the operators into the following groups:
1. Arithmatic Operators
2. Relational Operators
3. Logical Operators
4. Assignment Operators
5. Bitwise Operators
Arithmatic Operators:-
Arithmetic operators are used to perform common mathematical operations.
| Operator | Name | Example |
|---|---|---|
| + | Addition | x+y |
| - | Subtraction | x-y |
| * | Multiplication | x*y |
| / | Division | x/y |
| % | Modulus | x%y |
| ++ | Increment | ++x |
| -- | Decrement | --x |
Relational Operators:-
Comparison operators are used to compare two values.
Output is either true(1) or false(0)
| Operator | Name | Example |
|---|---|---|
| == | Equal to | x==y |
| != | Not Equal to | x!=y |
| > | Greater than | x>y |
| < | Lesser than | x<y |
| >= | Greater than or Equal to | x>=y |
| <= | Less than or Equal to | x<=y |
Logical Operators:-
Logical operators are used to determine the logic between variables or values:
| Operator | Name | Example |
|---|---|---|
| and | Logical and | x>y and x>10 |
| or | Logical or | x!=y or y<=6 |
| not | Logical not | not(y>x) |
Assignment Operators:-
Assignment operators are used to assign values to variables.
| Operator | Example | Same as |
|---|---|---|
| = | x=5 | x=5 |
| += | x+=5 | x=x+5 |
| -= | x-=3 | x=x-3 |
| *= | x*=4 | x=x*4 |
| /= | x/=y | x=x/y |
| %= | x%=9 | x=x%9 |
| &= | x&=1 | x=x&1 |
| |= | x|=3 | x=x|3 |
| ^= | x^=4 | x=x^4 |
| >>= | x>>=3 | x=x>>3 |
| <<= | x<<=3 | x=x<<3 |