# Python Operators With Examples

This article entitle Python Operators is a continuation of the previous article entitled Python Datatype.

Python Operators is a constructor that can use to manipulate the value of the operands. These operators are symbols which mainly used for a purpose of logical arithmetic and other various operations

## What are Python Operators?

In Python, operators are very special symbols that can be useful for the designation of some sort of calculation or computation that could need to be performed.

## Types of Operators in Python

The following list is the types of Python operators which have been supported.

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

## Logical Operators

Python Logical operators are mainly used to combine a conditional statement.

## Bitwise Operators

The bitwise operators are mainly used for comparing (binary) numbers.

Example

```a = 60            # 60 = 0011 1100
b = 13            # 13 = 0000 1101

# Binary AND
c = a & b        # 12 = 0000 1100
print ("a & b : ", c)

# Binary OR
c = a | b        # 61 = 0011 1101
print ("a | b : ", c)

# Binary XOR
c = a ^ b        # 49 = 0011 0001
print ("a ^ b : ", c)

# Binary Ones Complement
c = ~a;           # -61 = 1100 0011
print ("~a : ", c)

# Binary Left Shift
c = a << 2;       # 240 = 1111 0000
print ("a << 2 : ", c)

# Binary Right Shift
c = a >> 2;       # 15 = 0000 1111
print ("a >> 2 : ", c)```

Output

```a & b :  12
a | b :  61
a ^ b :  49
~a :  -61
a << 2 :  240
a >> 2 :  15
```

## Assignment Operators

Python assignment operator work is mainly used for assigning values to variables.

Example

```# Assignment Operator
a = 20

a += 6
print ("a += 5 : ", a)

# Subtraction Assignment
a -= 6
print ("a -= 5 : ", a)

# Multiplication Assignment
a *= 6
print ("a *= 5 : ", a)

# Division Assignment
a /= 6
print ("a /= 5 : ",a)

# Remainder Assignment
a %= 6

print ("a %= 3 : ", a)

# Exponent Assignment
a **= 2
print ("a **= 2 : ", a)

# Floor Division Assignment
a //= 3
print ("a //= 3 : ", a)```

Output

```a += 5 :  26
a -= 5 :  20
a *= 5 :  120
a /= 5 :  20.0
a %= 3 :  2.0
a **= 2 :  4.0
a //= 3 :  1.0
```

## Arithmetic Operators

The arithmetic operators are mainly used with numeric values in order to perform common mathematical operations.

Example

```x = 32
y = 15

print ("x + y : ", x + y)

# Subtraction
print ("x - y : ", x - y)

# Multiplication
print ("x * y : ", x * y)

# Division
print ("x / y : ", x / y)

# Modulus
print ("x % y : ", x % y)

# Exponent
print ("x ** y : ", x ** y)

# Floor Division
print ("x // y : ", x // y)```

Output

```x + y :  47
x - y :  17
x * y :  480
x / y :  2.1333333333333333
x % y :  2
x ** y :  37778931862957161709568
x // y :  2
```

## Membership Operators

The membership operators are mainly used to test if the sequence is already presented into an object.

## Identity Operators

The identity operators are mainly used for comparing an object if there are not equal, but once they actually have the same object with the same memory location.

## Comparison Operators

The Python comparison operators are mainly used for comparing two values

## Summary

In summary, you have read about Python Operators. We also discussed in this article what are Python Operators, and the different types of operators.