Python Operators are used to performing operations on different variables and values. These can be defined as the symbols that are responsible for a specific operation between two operands. Operators act as the pillars of a program based on which the logic is built in a particular programming language. There are numerous operators in Python which can be known in this below-mentioned article.

Following given is a variety of Python Operators:

**Arithmetic Operators**

Arithmetic operators are used to perform mathematic operations such as + (addition), – (subtraction), * (multiplication), / (division), % (remainder), // (floor division), and ** (exponent) between two operands.

Arithmetic Operators | Description | Example |
---|---|---|

+ | Addition: This specific arithmetic operator is used to add two operands. | x + y |

– | Subtraction : This specific arithmetic operator is used to subtract the second operand from the first one. In case the value of the first operand is less than the second one, then the result obtained will be negative. | x – y |

/ | Divide: This specific arithmetic operator returns the quotient after dividing the first operand by the second one. | x/y |

* | Multiplication : This specific arithmetic operator is used to multiply two operands. | x*y |

% | Remainder : This specific arithmetic operator returns the remainder after dividing the first operand with the second one. | x%y |

** | Exponent : This specific arithmetic operator is used to calculate the first operand power to the second operand. | x**y |

// | Floor division: This specific arithmetic operator gives the floor value of the quotient produced by dividing the two operands. | x//y |

# Examples of Arithmetic Operator a = 8 b = 6 # Addition of numbers add = a + b # Subtraction of numbers sub = a - b # Multiplication of number mul = a * b # Division(float) of number div1 = a / b # Division(floor) of number div2 = a // b # Modulo of both number mod = a % b # Power p = a ** b # print All Above Operator print(add) print(sub) print(mul) print(div1) print(div2) print(mod) print(p)

**Comparison Operators**

The main function of comparison operators is to compare the two values of the two operands and return the Boolean true or false, accordingly. Following mentioned are comparison Python Operators

Comparison Operators | Description | Example |
---|---|---|

> | Greater than: In case the value of the first operand is greater than the value of the second operand then it implies that the condition is true. | x>y |

< | Less than: In case the value of the first operand is less than the value of the second operand then it implies that the condition is true. | x<y |

== | Equal to: In case the value of two operands is equal then it implies that the condition is true. | x==y |

!= | Not equal to: In case the value of two operands is not equal then it implies that the condition is true. | x!=y |

>= | Greater than or equal to In case the value of the first operand is greater than or equal to the value of the second operand then it implies that the condition is true. | x>=y |

<= | Less than or equal to In case the value of the first operand is less than or equal to the value of the second operand then it implies that the condition is true. | x<=y |

**Bitwise Operators**

These are the types of Python Operators that perform a bit-by-bit operation on the values of the two operands. Following mentioned are bitwise operators used in Python:

Bitwise Operators | Description |
---|---|

& (binary and) | In case both the bits at the same place in the two operands are 1, then 1 is copied to the result. Otherwise, 0 will be copied. |

| (binary or) | In case both the bits at the same place in the two operands are 0, then 0 is copied to the result. Otherwise, 1 will be copied. |

^ (binary xor) | In case both the bits are different in the two operands are 1, then 1 is copied to the result. Otherwise, 0 will be copied. |

~ (negotiation) | It basically is used to calculate the negotiation of each bit of the operand. In case if the bit is 0, then the resulting bit will be 1 and vice-versa. |

<< (lest shift) | It is the bitwise operator using which the left operand value is moved left by the number of bits present in the right operand. |

>> (right shift) | It is the bitwise operator using which the left operand value is moved right by the number of bits present in the right operand. |

**Assignment Operators**

The main function of the assignment operators is to assign the value of the right expression to the left operand. Following mentioned are assignment Python Operators:

Assignment Operators | Description | |
---|---|---|

= | This assignment operator basically assigns the value of the right expression to the left operand. | x = y + z |

+= (Add AND): | It basically increases the left operand’s value by the right operand’s value and then assigns the modified value back to the left operand. For instance, | x+=y will be equal to x = x + y |

-= (Subtract AND) | It basically decreases the left operand’s value by the right operand’s value and then assigns the modified value back to the left operand. | x-=y will be equal to x = x-y |

*= (Multiply AND) | It basically multiplies the left operand’s value by the right operand’s value and then assigns the modified value back to the left operand. | x*=y will be equal to x = x*y |

%= (Modulus AND) | It basically modulates the left operand’s value by the right operand’s value and then assigns the result back to the left operand. | x%=y will be equal to x = x % y |

/= (Divide AND) | It basically divides the left operand’s value by the right operand’s value and then assigns the result back to the left operand. | x/=y will be equal to x = x/y |

//= [Divide(floor)AND] | It basically divides the left operand with the right operand and then assigns the value (floor) to the least operand. | x//=y will be equal to x = x//y |

**= (Exponent AND) | It is used to calculate the exponent (raise power) value by using the operands and assigns value to the left operand. | x**=y will be equal to x = x**y |

&= (Bitwise AND) | It basically performs bitwise AND on two operands and then assigns the value to the left operand. | x&=y will be equal to x = x & y |

|= (Bitwise OR) | It basically performs bitwise OR on the two operands and then assigns the value to the left operand. | x|=y x = x | y |

^= (Bitwise xOR) | It basically performs bitwise xOR on the two operands and then assigns the value to the left operand. | x^=y will be equal to x = x^y |

>>= (Bitwise Right) | It basically performs a bitwise right shift on the two operands and then assigns value to the left operand. | x>>=y will be equal to x = x>>y |

<<= (Bitwise left) | It basically performs a bitwise left shift on the two operands and then assigns value to the left operand. | x<<=y will be equal to x = x<<y |

**Logical Operators**

The logical Python Operators are primarily utilized in the expression evaluation to make a decision. Following mentioned are logical operators used in Python:

**Membership operators**

In Python, membership operators are utilized to check the membership of value inside the data structure of Python. In case the value is present in the data structure then the resulting value is true and vice-versa. Following mentioned are membership Python Operators:

Membership Operators | Description |
---|---|

in | It is evaluated to be true in case the first operand is found in the second one. |

not in | It is evaluated to be true in case the first operand is not found in the second one. |

**Identity operators**

The main function of identity operators is to decide whether an element certain class or type. Following mentioned are identity operators used in Python:

Identity Operators | Description |
---|---|

is | It is evaluated to be true in case the reference present at both sides point to the same object. |

is not | It is evaluated to be true in case the reference present at both sides does not point to the same object. |

**Operator Precedence**

It is essential to find out the operator precedence since it enables the users to know which operator is to be evaluated at first. Following given is the table of operators in Python:

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

** | The exponent operator is given priority over all others used in the expression. |

~ + – | The negotiation, unary plus, and minus. |

*/ % // | The multiplication, divide, modules, remainder, and floor division |

+ – | Binary plus, and minus |

>><< | Left shift and right shift |

& | Binary and |

<=<>>= | Comparison operators (less than, less than equal to, greater than, greater than equal to) |

<>==!= | Equality operators |

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

is is not | Identity operators |

in not in | Membership operators |

not or and | Logical operators |

^ | | Binary xor, and or |

So, these were Python operators** **that every beginner should know about.

Also, read *Simiservice.com*

- NASA Full Form – National Aeronautics and Space Administration - 4 August 2024
- What Is MS Word –Definition , Uses & Features - 28 July 2024
- Top Windows Networking Commands For Troubleshoot Network - 28 July 2024