# Python Operators Overview with Examples

Python Operators are used to performing operations on variables and values. The operators use numbers, strings other data types to get the action and application make math calculation or logic

In this tutorial, you will learn about different types of Python Operators, their syntax expression, and how to use them with examples.

Python language supports the following types of operators.

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

## Let’s see the one by one Python Operators :

#### Python Arithmetic Operators

You can perform math operation with Arithmetic’s operators, here are examples of Arithmetic’s operators :

```a = 10
b = 4
print("Addition : ", 10 + 4)
print("Subtraction : ", 10 - 4)
print("Multiplication : ", 10 * 4)
print("Division : ", 10 / 4)
print("Modulus : ", 10 % 4)
print("Exponentiation : ", 10 ** 4)
print("Floor division : ", 10 // 4)```

Subtraction : 6
Multiplication : 40
Division : 2.5
Modulus : 2
Exponentiation : 10000
Floor division : 2

### Python Assignment Operators

The assignment operators in Python are used to store data into a variable.

```a = 5

b = a
print("Assigns - value of b : ", b)

b += a
print("Add AND - value of b : ", b)

b -= a
print("Subtract AND - value of b : ", b)

b *= a
print("Multiply AND - value of b : ", b)

b /= a
print("Divide AND - value of b : ", b)

b %= a
print("Module AND - value of b : ", b)

b **= a
print("Exponent AND - value of b : ", b)

b //= a
print("Floor Division AND - value of b : ", b)```

Output : Assigns – value of b : 5
Add AND – value of b : 10
Subtract AND – value of b : 5
Multiply AND – value of b : 25
Divide AND – value of b : 5.0
Module AND – value of b : 0.0
Exponent AND – value of b : 0.0
Floor Division AND – value of b : 0.0

#### Python Comparison Operators

Let’s see the examples

```a = 10
b = 4
print("Equal : ", 10 == 4)
print("Not equal : ", 10 != 4)
print("Greater than : ", 10 > 4)
print("Less than : ", 10 < 4)
print("Greater than or equal to : ", 10 >= 4)
print("Less than or equal to: ", 10 <= 4)```

Output : Equal : False
Not equal : True
Greater than : True
Less than : False
Greater than or equal to : True
Less than or equal to: False

### Python Logical Operators

```a = 10
b = 4
print("and : ", a < 5 and b < 10)
print("or : ", a < 5 or b < 10)
print("not : ", not(a < 5 and b < 10))
```

Output : and : False
or : True
not : True

### Python Membership Operators

Python membership operators test(search or find) for membership in a sequence, such as strings, lists, or tuples. There are two membership operators as below :

Returns True if a sequence with the value is in the list else False

```colorList = ["red", "yellow", "black"]

print("red" in colorList)
print("orange" in colorList)

print("red" not in colorList)```

Output : True
False
False

### Python Identity Operators

Example

```a = 10
b = a
print("is : ", a is b)
print("is not : ", a is not b)```

Output: is : True
is not : False

Do comment if you have any doubts and suggestions on this tutorial.

Note : All Python Operators examples is developed in PyCharm 2018.2 (Community Edition)
JRE: 1.8.0
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6

Python 3.7

All Examples of Operators are in Python 3, so it may change its different from python 2 or upgraded versions.

This site uses Akismet to reduce spam. Learn how your comment data is processed.