# Operators in Python

**Operators**

**Operators are used to performing some operation between some values of any data types. We have seven different types of Operators in Python and can perform any operation but are differentiated according to their usage. Like when we add two numbers we use addition operators between those numbers which can be int, or float, or can be of another data type.**

**Arithmetic operators are used to performing mathematical operations like addition, subtraction, multiplication, division, etc. Arithmetic operators can be set in between operands. In mathematical operations elements on which operation is supposed to be done are called operand and the type of operation is performed by the operator used between two operands.**

Operator | Name of Operator | Example |
---|---|---|

+ | Addition | Prep + Insta |

– | Subtraction | Prep – Insta |

* | Multiplication | Prep * Insta |

/ | Division | Prep / Insta |

% | Modulus | Prep % Insta |

** | Exponentiation | Prep ** Insta |

// | Floor Division | Prep // Insta |

**The assignment operator is used to assigning values to the variable in many different ways, we can assign values by incrementing, decrementing, or by performing any other operation and then assigning the value to the variable. We have 13 assignment operators to assign values to the variable.**

Operator | Also be used as | Example |
---|---|---|

= | a = 5 | a = 5 |

+= | a = a+5 | a+=5 |

-= | a = a-5 | a-=5 |

*= | a = a * 5 | a*=5 |

/= | a = a/5 | a/=5 |

%= | a = a%5 | a%=5 |

//= | a = a//5 | a//=5 |

**= | a = a **5 | a**=5 |

&= | a = a&5 | a&=5 |

|= | a = a|5 | a|=5 |

^= | a = a^5 | a^=5 |

>>= | a = a>>5 | a>>=5 |

<<= | a = a<<5 | a<<=5 |

Operator | Name of Operator | Example |
---|---|---|

== | Equal | a == b |

!= | Not equal | a != b |

> | Greater than | a > b |

< | Less than | a < b |

>= | Greater than or equal to | a >= b |

<= | Less than or equal to | a <= b |

**The logical operator is used to perform some logical operations or combine conditional statements. Mainly logical operators are used in control statements like if, else, and elif where we can check more conditions together just by using these operators. Logical operators always return TRUE or FALSE values.**

Operator | About | Example |
---|---|---|

and | TRUE if both are true | a > 5 and a > 10 |

or | TRUE if any one is true | a > 5 or a > 10 |

not | Converts TRUE to FALSE | not(TRUE) |

**Identity operators are used in Python programing language to check if the two values, variables, or constants are not only the same but also have the same memory location. These types of operators are used to compare and check the exact match of the values between two objects.**

Operator | About | Example |
---|---|---|

is | Returns TRUE if a and b both are same | a is b |

is not | Return TRUE if a and b both are not same | a is not b |

**Membership operators are used for checking if the iterator or the given value is present in the sequence or not. These types of operators always return values in a TRUE or FALSE format. If the value is found in the sequence then the operator will return TRUE else the operator will return FALSE.**

Operator | About | Example |
---|---|---|

in | Returns TRUE if the iterator is present in sequence | a in b |

not in | Returns TRUE if the iterator is not present in sequence | a not in b |

**These operators are used to compare the binary numbers. We can perform different operations on binary numbers such as and, or, xor, not, left shift, and right shift. Sometimes these operators are also called bitwise-or, bitwise-and, and bitwise-xor and so on. Shift operators are used to shifting the values of the binary number to left or right.**

Operator | Name | About |
---|---|---|

& | AND | Return 1 if both are TRUE or 1 |

| | OR | Return 1 if one of them are TRUE or 1 |

^ | XOR | Return 1 if only one is TRUE or 1 |

~ | NOT | Inverse |

<< | Left shift | Shifting bits to the left |

>> | Right shift | Shifting bits to the right |

Login/Signup to comment