# Operators in Python

In this tutorial, we will learn about Operators in Python. Operators are special symbols which normally use to perform some special task in the program. For example, you want to add two number. Here we will use + operator to add two numbers or you want to assign value to a variable. Here we will use = assignment operator to assign value to a variable. There are so many operators available in Python and they are divided into different categories. We learn here all the categories.

## Arithmetic operators:

Arithmetic operators are so simple. Arithmetic operators are used to performing simple mathematical computations like addition, subtraction, multiplication and division. There are total seven operators in this category and these are as follow.

## Example of Arithmetic Operators in Python:

```num1 = 20
num2 = 5

# Output: num1 + num2 = 25
print('num1 + num2 =',num1+num2)

# Output: num1 - num2 = 15
print('num1 - num2 =',num1-num2)

# Output: num1 * num2 = 100
print('num1 * num2 =',num1*num2)

# Output: num1 / num2 = 4.0
print('num1 / num2 =',num1/num2)

# Output: num1 // num2 = 4
print('num1 // num2 =',num1//num2)

# Output: num1 ** num2 = 3200000
print('num1 ** num2 =',num1**num2)```

## Identity Operators:

Identity Operators are used to comparing two objects. It will return true if both objects share the same memory location.

## Example of Identity operators in Python:

```str1 = "Owlbuddy"
str2 = str1

print(str1 is str2)

print(str1 is not str2)```

## Membership Operators:

Membership operators in Python are used to check if a sequence is present in Object.

## Example of Membership operators in Python:

```names = ["Ravi", "Gurpreet"]

print("Ravi" in names)

print("Hardeep" not in names)```

## Comparison operators:

Comparison operators are used to comparing two values in Python and the result of this comparison will come like true or false. Here are some operators which come in this category.

## Example of Comparison operators in Python:

```num1 = 20
num2 = 25

# Output: num1  > num2 is False
print('num1  > num2  is',num1 > num2)

# Output: num1 < num2 is True
print('num1 < num2  is',num1 < num2)

# Output: num1 == num2 is False
print('num1 == num2 is',num1 == num2)

# Output: num1 != num2 is True
print('num1 != num2 is',num1 != num2)

# Output: num1 >= num2 is False
print('num1 >= num2 is',num1 >= num2)

# Output: num1 <= num2 is True
print('num1 <= num2 is',num1 <= num2)```

## Logical operators in Python:

Logical operators are used to making comparison between two expressions. There are three logical operators in Python.

## Example of Logical operators in Python:

```x = True
y = False

# Output: Result of x and y is False
print('Result of x and y is',x and y)

# Output: Result of x or y is True
print('Result of x or y is',x or y)

# Output:Result of  not x is False
print('Result of not x is',not x)```

## Assignment operators in Python:

Assignment operators are used to assigning value to a variable in Python. There is a rich collection of assignment operators in Python.

## Example of Assignment Operators in Python:

```num = 3
print("Value of num= "+num)

num+=10
print("Value of num= "+num)

num-=5
print("Value of num= "+num)

num*=2
print("Value of num= "+num)

num/=2
print("Value of num= "+num)

num%=2
print("Value of num= "+num)```