Operators in Python

10 August 2023

|
3 min read

Blog Image

In Python, an operator is a symbol that represents a specific action or operation that can be performed on one or more values. Operators are used to manipulating and performing calculations on data values in Python. Python supports various operators, which can be classified into several categories:

Arithmetic operators:

These operators are used to perform basic mathematical operations such as addition, subtraction, multiplication, division, modulus, and exponentiation. The following are the arithmetic operators in Python

+ (addition) - (subtraction) * (multiplication) / (division) % (modulus) ** (exponentiation) // (floor division)

Comparison operators:

These operators are used to compare two values and return a boolean value (True or False) based on the comparison. The following are the comparison operators in Python:

== (equal to) != (not equal to) > (greater than) < (less than) >= (greater than or equal to) <= (less than or equal to)

Logical operators:

These operators are used to combine multiple conditions and return a boolean value based on the result. The following are the logical operators in Python:

(logical and) or (logical or) not (logical not)

Wondering what interviewers ask about Python Data Structures? Find out in our latest TrainingHub.io blog!

Bitwise operators:

These operators are used to perform bitwise operations on integers. The following are the bitwise operators in Python:

& (bitwise and) | (bitwise or) ^ (bitwise exclusive or) ~ (bitwise not) << (left shift) >> (right shift)

Assignment operators:

These operators are used to assign values to variables. The following are the assignment operators in Python:

= (simple assignment) += (add and assign) -= (subtract and assign) *= (multiply and assign) /= (divide and assign) %= (modulus and assign) **= (exponentiation and assign) //= (floor division and assign) &= (bitwise and and assign) |= (bitwise or and assign) ^= (bitwise exclusive or and assign) <<= (left shift and assign) >>= (right shift and assign)

Identity operators:

These operators are used to compare the identity of two objects. The following are the identity operators in Python:

is (returns Trueif two variables refer to the same object) isnot (returns Trueif two variables do not refer to the same object)

Membership operators:

These operators are used to check if a value is a member of a sequence. The following are the membership operators in Python:

in (returns Trueif a value is found in a sequence) notin (returns Trueif a value isnot found in a sequence)

These operators can be used in various ways to perform different types of operations in Python.

For those aspiring to enhance their skills in Python, delve into our Python Training program at TrainingHub.io

Suggested blogs