# The Python Operators

In the Python Language, variables hold data values that convey the message. These values are either for logical or arithmetic operations. Meaning on python, all the process of writing codes is done using the standard python Operators. In a very simple and clear manner, you’ll be learning the python Operators, what is it, the features of python Operators, and also you’ll be knowing the types and functions of Python Operators. For the practical aspect, you’ll know how to apply them to Python Language, before that you will learn how to access the python operator Values. In conclusion, you’ll be able to update the python Operators and delete some unwanted operations.

Contents

## What are Python Operators

Python Operators are standard symbols that are used for the logical and arithmetic operations in Python. Operators are used with operands to return a value e.g 2+8=10, 2 and 8 are the operands,(+) is the operator and the returned Value or output is 10. Python has seven (7) Operators and they are:

1. Arithmetic Operators
1. Comparison/Relational Operators
1. Assignment Operators
1. Logical Operators
1. Bitwise Operators
1. Membership Operators
1. Identity Operators

This page is dedicated to giving complete knowledge of these operators.

## Arithmetic Operators

The Arithmetic Operators are used to carry out all arithmetic or mathematical activities on python. Mathematical operations like addition, subtraction, multiplication, and division are enabled by the mathematical symbols: ( +, -, /, *). See the table for a complete arithmetic Operators symbols

### Example of Arithmetic Operators

Note: all the above examples will be shown at once. Take x=9 and y=4

Python Input:

```# Examples of Arithmetic Operator
x = 9
y = 4
# Addition of numbers
add = x + y
# Subtraction of numbers
sub = x - y
# Multiplication of a number
mul = x * y
# Division(float) of number
div1 = x / y
# Division(floor) of number
div2 = x // y
# Modulo of both numbers
mod = x % y
# Power
p = x ** y
# print results
print(sub)
print(mul)
print(div1)
print(div2)
print(mod)
print(p)

```
```Output:

13
5
36
2.25
2
1
6561```

The above returns explain the arithmetic Operators practically

## Comparison Operators in Python

Comparison Operators in Python are used to compare values. It gives True or False according to the condition. The python comparison Operators are also called Relational Operators. Take x and y as our two values

### Example of comparison Operators in Python

Take x=11 and y=22

Python input:

```# Examples of Relational Operators
x = 11
y = 22
# x > y is False
print(x > y)
# x < y is True
print(x < y)
# x == y is False
print(x == y)
# x != y is True
print(x != y)
# x >= y is False
print(x >= y)
# x <= y is True
print(x <= y)

```
```Output:

False
True
False
True
False
True```

The above returns a practical explanation of the python comparison Operators

## Assignment Operators

As the name implies, assignment Operators are used to assign values to variables in Python. Meaning all characters must have the assignment symbol (=).  Let’s see the tablet with x and y as our operands

### Some examples of assignment Operators on Python

Python Input:

```# Examples of Assignment Operators
x = 20
# Assign value
y = x
print(y)
# Add and assign value
y  += x
print(y)
# Subtract and assign value
y -= x
print(y)
# multiply and assign
y *= x
print(y)
# bitwise shift operator
y <<= x
print(y)

```
```Output:

20
40
20
200
204800```

The above examples show the assignment Operators practically

## Python Logical Operators

Logical operators are used to join conditional statements to give logical output. It uses the Logical AND, Logical OR, and Logical NOT operations.

See the table for all Logical Operators in Python

### Example of Python Logical Operators

Python input:

```# Examples of Logical Operator
x = True
y = False
# Print a and b is False
print(x and y)
# Print a or b is True
print(x or y)
# Print, not a is False
print(not x)

```
```Output:

False
True
False```

The above expresses the Python Logical Operators in a practical order

## Bitwise Operators in Python

These are the bit-by-bit binary numbers operations on Python. Some examples of the Bitwise operators and syntax are expressed in the table below

### Example of Python Bitwise operators

Python Input:

```# Examples of Bitwise operators
x = 10
y = 4
# Print bitwise AND operation
print(x & y)
# Print bitwise OR operation
print(x | y)
# Print bitwise NOT operation
print(~x)
# print bitwise XOR operation
print(x ^ y)
# print bitwise right shift operation
print(x >> y)
# print bitwise left shift operation
print(x << y)

```
```Output:

0
14
-11
14
2
40```

## Membership Operators

The membership Operators check whether a variable or value is included in a sequence. It uses not or not in as its operators.

• in signifies true if a value or variable is found in a sequence
• not in returns false if a value or variable is not in a sequence

### Example of Python Membership Operators

```# Python program to illustrate
# not 'in' operator
x = 24
y = 20
list = [10, 20, 30, 40, 50]
if (x is not in the list):
print("x is NOT present in the given list")
else:
print("x is present in the given list")
if (y in the list):
print("y is present in the given list")
else:
print("y is NOT present in the given list

```
```Output:

x is NOT present in the given list
y is present in the given list```

## Python Identify Operators

The identity operators identify and compare the memory location of two objects. The identity operators operate in two categories which are:

• is: Simply true if the Values are similar( x is y)
• is not: Signifies true is the values are not similar (x is not y)

### Example Of Python Identify Operators

Python Input:

```x = 10
y = 20
v = a
print(x is not y)
print(x is c)

```
```Output:

True
True```

## Python Precedence Operators

Python Precedence Operators are used in an operation with more than one operator to indicate which operator should operate first. It determines operations according to priority.

The Table Below Shows all python’s precedence from highest to lowest

### Example of Python Precedence Operators

Python Input:

```# Examples of Operator Precedence
# Precedence of '+' & '*'
expr = 1 + 50 * 10
print(expr)
# Precedence of 'or' & 'and'
name = "Simon"
age = 0
if name == "Simon" or name == "Monday" and age >= 2:
print("Hello! Tanya.")
else:
print("Good-Bye!!")

```
```Output:

501
Hello! Tanya.```

From the above output, python prints according to precedence.

## Summary

In the Python Language, variables hold data values that convey the message. These values are either for logical or arithmetic operations.

Python Operators are standard symbols that are used for logical and arithmetic operations on Python.

Python Precedence Operators are used in an operation with more than one operator to indicate which operator should operate first. It determines operations according to priority.

In this topic, you have been taught extensively on Python Operators and all the Python Precedence Operators. It’s all on you to give the theory some practice for maximum results. For a headstart check out the python tutorials. Good luck Coding! Hi, I’m Pramod Kumar Yadav & a computer science Engineer with 3years of experience in Digital marketing. I’m self-motivated and love to do SEO.