Operators are the constructs that are used to manipulate the value of operands. Some basic operators include **+, -, *, and / **. In an expression, an operator is used on operand(s) (values to be manipulated). For example, in the expression **sum = a + b**, **a** and **b** are operands and **+ **is the operator.

Python Supports different types of operators which are as follows –

- Arithmetic Operators
- Comparison Operators
- Assignment Operators
- Logical Operators
- Bitwise Operators
- Membership Operators
- Identity Operators

## 1 . Arithmetic Operators –

Some basic arithmetic operators are **+, -, *, /, %, **** and **//**. You can apply these operators on numbers as well as on variables to perform corresponding operations. For example if **a=100 and b=200**, then look at the below table to see the result of operations.

Operator | Description | Example | Output |
---|---|---|---|

+ | Addition – Add the operands | a + b | 300 |

– | Subtraction – subtracts operand on the right from the operand on the left of the operator | a – b | -100 |

* | Multiplication – Multiplies the Operands | a * b | 20000 |

/ | Division – Divides operand on the left side of the operator with the operand on its right. The division operator returns the quotient. | b / a | 2.0 |

% | Modulus – Divides operand on the left side of the operator with the operand on its right. The modulus operator returns the remainder. | b % a | 0 |

// | Floor Division – Divides the operands and returns the quotient. It also removes the digits after the decimal point. If one of the operands is negative, the result is floored (i.e. rounded away from zero towards negative infinity) | 12 // 5 | 2 |

** | Exponent – Performs exponential calculation that is raises operand on the right side to the operand on the left of the operator. | a**b | 100**200 |

## 2 . Comparison Operators –

Comparison operators also known as relational operators are used to compare the values on its either sides and determines the relation between them. For example assuming **a = 100 and b = 200**, we can use the comparison operators on them as specified in the below table.

Operator | Description | Example | Output |
---|---|---|---|

== | Returns True if the two values are exactly equal. | a == b | False |

!= | Returns True if the two values are not equal. | a != b | True |

> | Returns True if the value at the operand on the left side of the operator is greater than the value on its right side. | a > b | False |

< | Returns True if the value at the operand on the right side of the operator is greater than the value on its left side. | a < b | True |

>= | Return True if the value of the operand on the left side of the operator is either greater than or equal to the value on its right side. | a >= b | False |

<= | Returns True if the value at the operand on the right side of the operator is either greater than or equal to the value on its left side. | a <= b | True |

## 3 . Assignment Operators –

Assignment operator as the name suggests assigns value to the operand. The in-place operators also known as shortcut operators that includes **+=, -=, *=, /=, %=, //= and **=** allow you to write code like num = num + 10 more concisely as num += 10. The different types of assignment and in-place operators are given in the table below.

Operator | Description | Example |
---|---|---|

= | Assign value of the operand on the right side of the operator to the operand on the left | c = a, assigns value of a to the variable c |

+= | Add and assign – Adds the operands on the left and right side of the operator and assigns the result to the operand on the left. | a += b is same as a = a + b |

-= | Subtract and assign. Subtracts operand on the right from the operand on the left of the operator and assigns the result to the operand on the left | a -= b is same as a = a – b |

*= | Multiply and assign – Multiplies the operands and assigns result to the operand on the left side of the operator. | a *= b is same as a = a * b |

/= | Divide and assign – Divides operand on the left side of the operator with the operand on its right. The division operator returns the quotient. The result is assigned to the operand to the left of the division operator. | a /= b is same as a = a / b |

%= | Modulus and assign. Divides operand on the left side of the operator with the operand on its right. The modulus operator returns the remainder which is then assigned to the operand on the left of the operator. | a %= b is same as a = a % b |

//= | Floor division and assign – Divides the operands and returns the quotient. It also removes the digits after the decimal point. If one of the operands is negative, the result is floored (rounded away from zero towards negative infinity) the result is assigned to the operand on the left of the operator. | a //= b is same as a = a // b |

**= | Exponent and assign – Performs exponential calculation that is raises operand on the right side of the operand on the left of the operator and assigns the result in the left operand. | a **= b is same as a = a**b |

## 4. Bitwise Operators –

As the name suggests, bitwise operators performs operations at the bit level. Bitwise operators expect their operands to be of integers and treat them as a sequence of bits.

Operator | Name | Description |
---|---|---|

& | 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 | Inverts all the bits |

<< | Zero fill left shift | Shift left by pushing zeros in from the right and let the leftmost bits fall off |

>> | Signed right shift | Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off |

## 5 . Logical Operators –

Logical operators are used to combine conditional statements.

Operator | Description | Example |
---|---|---|

and | True if both the operands are true. | x and y |

or | True if either of the operands is true | x or y |

not | True if operand is false (complements the operand) | not x |

## 6. Membership Operators –

Membership operators are used to test if a sequence is presented in an object.

Operator | Description | Example |
---|---|---|

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. 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.

Operator | Description | Example |
---|---|---|

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 |

## Operators Precedence and Associativity –

The below table lists all operators from highest precedence to lowest. When an expression has more than one operator then it is the relative priorities of the operators with respect to each other that determine the order in which the expression will be evaluated.

Operator | Description |
---|---|

** | Exponentiation |

~, +, – | Complement, unary plus (positive) and minus (negative) |

*, /, %, // | Multiply, divide, modulo, and floor division |

+, – | Addition and subtraction |

>>, << | Right and left bitwise shift |

& | Bitwise AND |

^, | | Bitwise exclusive OR and regular OR |

<=, <, >, >= | comparison operators |

<>, ==, != | Equality operators |

=, %=, /=, //=, -=, +=, *=, **= | Assignment operators |

is, is not | Identity operators |

in, not in | Membership operators |

not, or , and | Logical Operators |