Operators In Python

Definition

Operators are the constructs which can manipulate the value of operands.

Consider the expression 4 + 5 = 9. Here, 4 and 5 are called operands and + is called operator.

Types of Operator

Python language supports the following types of operators.

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

Let us have a look on all operators one by one.

Python Arithmetic Operators

Python Comparison Operators

These operators compare the values on either sides of them and decide the relation among them. They are also called Relational operators

Python Assignment Operators

Python Bitwise Operators

Bitwise operator works on bits and performs bit by bit operation.

In the table below: Let x = 10 (0000 1010 in binary) and y = 4 (0000 0100 in binary)

Python Logical Operators

There are following logical operators supported by Python language.

let us understand it with example

Python Membership Operators

Python’s membership operators test for membership in a sequence, such as strings, lists, or tuples. There are two membership operators as explained below −

Python Identity Operators

Identity operators compare the memory locations of two objects. There are two Identity operators explained below −

Python Operators Precedence

The following table lists all operators from highest precedence to lowest.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store