# Python Operators

An operator is a symbol that performs an operation on values and variables. You can use the following operator types in Python:

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

## Arithmetic Operators

Arithmetic operators are used to perform arithmetic operations like addition, subtraction, multiplication, division, etc.

## Comparison Operators

Comparison operators are used to compare two values and return a boolean result (true/false).

In Python 2, both `!=` and `<>` are used as Inequality Operator (a != b) (a <> b).
In Python 3, `<>` is removed, only `!=` is used for inequality comparison.

## Assignment Operators

Assignment operators are used to assign right-side expressions to left-side variables.

## Logical Operators

There are 3 logical operators in Python: AND, OR and NOT. These operators are mainly used in conditional statements.

## Bitwise Operators

Bitwise operators are used to perform operations on individual bits in a number.

Bitwise Inversion of a number `x` is calculated as `-(x+1)`. For instance, bitwise inversion of 151 (10010111) is -152 (-10011000).

## Membership Operators

Membership operators are used to check the appearance of a value within a sequence like lists, strings or tuples. There are two membership operators in Python: IN, NOT IN

For the examples below consider prime list is defined as:

```primes = [2, 3, 5, 7, 11]
```

## Identity Operators

Identity operators are used to check whether two objects refer to the same object. There are two identity operators in Python: IS, IS NOT

For the examples below consider the code below. Both `var1` and `var2` have the same content but they are distinct objects in memory. `var3`, on the other hand, refers to the same object as var1.

```var1 = ["Hello", "World"]
var2 = ["Hello", "World"]
var3 = var1

print(var1 is var2)
print(var1 is var3)
```

You can also use identity operators to check the type of an object.
Since the type of `var1` is list, following code prints TRUE.

```print(type(var1) is list)
```