Saturday, February 1, 2020


Operators in Python

In a programming language, an operator is a special symbol that is used to carry out some kind of computation (eg. arithmetic, logical, etc.) operation.

Python has following operators
  • Arithmetic operators 
  • Assignment operators
  • Logical operators
  • Bitwise operators
  • Comparison operators
  • Membership operators

Arithmetic operators

Arithmetic operators are used to performing a general Arithmetic operation.

Assignment operators

Assignment operators are used to assigning some value to a variable. (equal to)  = is the basic assignment operator. We can use = operator with other operators to assign values.


Comparison and Identity check operators

strictly less than
less than or equal
strictly greater than
greater than or equal
not equal
object identity
is not
negated object identity

We can compare operands using these operators.

is and is not operator

The is and is not operators are used to test for the object's identity. If x and y are two objects then, x is y is True if and only if x and y are the same objects. is not is just vice versa to is the operator.

For example

Logical operators

Logical operators like AND, OR, and NOT are used to apply logical operations over operands.

For example,

Bitwise operators

These operators work on bits of objects, standard and, or, xor, not, and shift operators are available in Python.

Membership operators

These operators are used to check the presence of an element in a collection or sequence.

For Example