In this article, I am going to discuss Operators in Python with Examples. In programming languages, an operator is a symbol that is applied to some operands i.e. variables, to perform certain operations on it.

Types Of Operators in Python:

Following is the summary of Python operators:

  • Arithmetic Operators: The operators which are used to perform arithmetic operations like addition, subtraction, division etc. They are: +, -, *, /, %, **, //
  • Relational Operators: The operators which are used to check for some relation like greater than or less than etc. between operands are called relational operators. They are: <, >, <=, >=, ==, !=
  • Logical Operators: The operators which do some logical operation on the operands and return True or False are called logical operators. The logical operations can be ‘AND’, ‘OR’ etc.
  • Assignment Operators: The operators which are used for assigning values to variables. ‘=’ is the assignment operator.
  • Unary Minus Operator: The operator ‘-’ is called the Unary minus operator. It is used to negate the number.
  • Membership Operators: The operators that are used to check whether a particular variable is part of another variable or not. They are ‘in’ and ‘not in’
  • Identity Operators: The operators which are used to check for identity. They are ‘is’ and ‘is not’

Examples of Python Operators:

Arithmetic operators are used with numeric values to perform common mathematical operations:

x + y    # Addition
x - y    # Subtraction
x * y    # Multiplication
x / y    # Division
x % y    # Modulus
x ** y   # Exponentiation
x // y   # Floor division 


x == y   # Equal
x != y   # Not equal
x > y    # Greater than
x < y    # 	Less than
x >= y   # Greater than or equal to
x <= y   # Less than or equal to


x < 5 and  x < 10      # Returns True if both statements are true
x < 5 or x < 4         # Returns True if one of the statements is true
not(x < 5 and x < 10)  # Reverse the result, returns False if the result is true


x is y               # Returns True if both variables are the same object
x is not y           # Returns True if both variables are not the same object


x in y              # Returns True if a sequence with the specified value is present in the object
not in y            #Returns True if a sequence with the specified value is not present in the object


x & y            #  Sets each bit to 1 if both bits are 1
x | y            #  Sets each bit to 1 if one of two bits is 1
x ^ y            # Sets each bit to 1 if only one of two bits is 1
~x               # Inverts all the bits
x << 2           # Shift left by pushing zeros in from the right and let the leftmost bits fall off.
x >> 2           # Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off.

Operator Precedence

Operator precedence describes the order in which operations are performed. Parentheses has the highest precedence, meaning that expressions inside parentheses must be evaluated first and then outer.

print((2 + 3) - (2 + 3))

Explore More

end and sep in Python

end in Python The end is a parameter in Python’s built-in print() function/method that controls what character(s) are printed at the end of the printed text.  Syntax : Output :

Input and Output in Python

Understanding input and output operations is fundamental to Python programming. With the print() function, you can display output in various formats, when the input() function/method enables interaction with users by gathering

f-strings in Python

Python offers a powerful feature called f-strings (formatted string literals) to simplify string formatting and interpolation. f-strings is introduced in Python 3.6 it provides a concise and intuitive way to embed expressions and variables