# 7 Python Operators with Examples

We are going to cover Python Operators with Examples , python Arithmetic Operators, python Logical operators, python Comparison operators, python Assignment operators, python Bitwise operators, python Identity operators, python Membership operators

### What is Operator in Python ?

Operators are special symbols used to perform operations. The value that the operator operates on is called the operand.

For Example, 2+5=7 here, 2 and 5 are called operands and + is an operator that performs addition.

## #1:Python Arithmetic Operators:

Arithmetic Operators are used to perform mathematical calculations on numeric data. And perform operations like addition, subtraction, multiplication and division.

Examples of Arithmetic Operators

``````a = 7
b = 2
#subtraction
sub = a – b
#multiplication
mul = a * b
#division
div = a / b
#Floor division
div_floor = a // b
#Modulus
mod = a % b
# Exponent(power)
power = a ** b
#print
print(sub)
print(mul)
print(div)
print(div_floor)
print(mod)
print(power)``````

## #2: Python Logical Operators:

Logical operators allow a program to make a decision based on multiple conditions. Each operand is considered a condition that can be evaluated to a true or false value. Then the value of the conditions is used to determine the overall value of the operand1 operator operand2. Logical operators perform Logical AND, Logical OR and Logical NOT operations.

Examples of python Logical Operators

``````a = True
b =  False
# and
print(a and b)
# or
print(a or b)
# not
print(not a)
output:
False
True
False``````

## #3: Python Comparison Operators:

In python Comparison Operators are also called as relational operators in python.  Comparison operators compare the value.

It returns True or False according to the condition.

In python there are different types of comparison operators like less than, greater than, equal to and not equal to.

Examples of python comparison operators

``````a = 12
b = 10

# it returns True because 12 is greater than 10
print(a > b)

# it returns False because 12 is not less than 10
print(a < b)

# it returns False because 12 is not equal to 10
print(a == b)

# it returns True because 12 is not equal to 10
print(a != b)

# it returns True because 12 is greater than or equal to 10
print(a >= b)

# it returns False because 12 is neither greater than or equal to 10
print(a <= b) ``````

## #4: Python Assignment Operators:

In python, assignment operators  are used to assign value to variables.

Examples of python assignment operators

``````a = 7
print(a)
a + = 7
print(a)
#Sub AND
a - = 7
print(a)
#Mul AND
a * = 7
print(a)
#Div AND
a / = 7
print(a)
#Div Floor AND
a // = 7
print(a)
#Mod AND
a % = 7
print(a)
#Exponent AND
a ** = 7
print(a)
#Bit Right
a >> = 7
print(a)
#Bit Left
a << =7
print(a)
#Bit AND
a & = 7
print(a)``````

## #5: Python Bitwise Operators:

In Bitwise operator operations are done in bit-level. In this operators are used to compare numbers

Examples of python Bitwise Operators

``````a = 12
b = 25
print(a & b)
print(a|b)
print(a ^ b)
print(~ a)
print(a>>4)
print(a<<2)``````

## #6: Python Identity Operators:

Identity Operator is used to compare the object memory location. It checks if two values are located in the same part of memory.

If two values are the same that does not mean they are identical.

Examples of Python Identity Operators

``````x = 'FOSSTechNix'
y = 'FOSSTechNix'
x1 = ["a","b","c"]
y1 = ["a","b","c"]
# True because y is same as x
print(x is y)
# False because y and x same
print(x is not y)
# True because x and y is equal
print(x == y)
# False because x and y is equal
print(x != y)``````

## #7: Python Membership Operators:

Membership Operators are used to check value is in sequence

Examples of Python Membership Operators

``````x = ["a","b","c"]
y = "FOSSTechNix"
# in
print("FOSS" in y)
print("FOSS" in x)
# not in
print("d" not in x)
print("a" not in x)``````

We have covered Python operators with Examples.

Conclusion:

We have covered Python operators with Examples , python Arithmetic Operators, python Logical operators, python Comparison operators, python Assignment operators, python Bitwise operators, python Identity operators, python Membership operators

Related Articles:

Python Introduction for Programmers [Part 1]

Python Conditional Statements with Examples

Loops in Python with Examples

Functions in Python with Examples

classes and objects in python with examples

Reference:

Python Official Page

0 Shares ##### Shweta Mamidwar

I am Shweta Mamidwar working as a Intern in Product Company. Likes to share knowledge.

### 7 thoughts on “7 Python Operators with Examples”

1. Nice info dear

• thanks.

2. Useful & Nice Information
Very good

3. Interesting

• thanks

4. Good jobs dear

5. 