## Python: Operators

The heart, the soul, and the foundation of any programming language, are it’s operators. They help build the logic, and transform your ideas into functioning models. They can manipulate values, functions, and help achieve our targets when used effectively.

## Types of Operators

Python language supports the following types of operators.

• Arithmetic
• Assignment
• Bitwise
• Comparison (Relational)
• Identity
• Logical
• Membership

Now, we shall look at each arithmetic operator with examples, so that it will be a lot easier for one to understand, how does Python, and their operators, really work!

## Python Arithmetic Operators

Let’s assume we have two variable, a =5 and b = 10. Thus:

## Python Comparison Operators

These operators compare the values on either sides of them and decide the relation among them. They are also called Relational operators.

Let’s assume we have two variable, a =5 and b = 10. Thus:

## Python Assignment Operators

Let’s assume we have two variable, a =5 and b = 10. Thus:

## Python Bitwise Operators

Bitwise operator works on bits and performs bit by bit operation. Assume if a = 60; and b = 13; Now in binary format they will be as follows −

a = 0011 1100

b = 0000 1101

—————–

a&b = 0000 1100

a|b = 0011 1101

a^b = 0011 0001

~a  = 1100 0011

There are following Bitwise operators supported by Python language

## Python Logical Operators

There are following logical operators supported by Python language. Let’s assume we have two variable, a =5 and b = 10. Thus:

## Python Membership Operators

Python’s membership operators test for membership in a sequence, such as strings, lists, or tuples. There are two membership operators as explained below:

## Python Identity Operators

Identity operators compare the memory locations of two objects. There are two Identity operators explained below −

## Python Operators Precedence

The following table lists all operators from highest precedence to lowest.

In case, you have any questions, feel free to mention your questions as comments to this specific post. I will try and answer at the earliest.