# What are the Operators in Python Language? Explained in Details ## What are the Operators?

Operators are used to performing operations on variables as well as values. These are special symbols that use to carry out arithmetic as well as logical operations. The value that the operator operates on is Operand. Operators can manipulate individual items and returns results. The data items are referred to as operands or arguments.

#### Consider an example:

8 + 5 = 13. So here 8 and 5 are called operands and whereas + is Operator.

## Arithmetic Operator

Arithmetic operators are used to perform arithmetic operations between variables. In Python assignment operators are used for assigning the values of the right operand to the left operand. There are many methods for calculations like eval function, call function, declare variable etc. Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, division etc.

## Assignment Operator

The assignment operator is used to assign values into variables. The assignment operator works from right to left. It means that the value of its RHS is copied to LHS must be a variable or some container and its RHS may be variable, literal or equation.

## Logical Operator

Logical Operator are used for conditional statements are true or false. In python logical operator are AND, OR, NOT.

For AND operator: This operator returns true but with mandatory condition if both the operands are true.

For OR operator: This operator returns true if either of the operand is true.

For NOT operator: This operator returns true if operand is false.

## Comparison Operator

Comparison operator are used to compare values. It either returns true or false according to the condition mentioned. These operators are also known as relational operator. No operator precedence in comparison operator. In comparison operator we compare the given values like x and y for resultant.

These operator are used (==,!=, >, <, >=, <=)

#### Examples:

Membership Operator

The operator are used to validate the membership of value. It test for membership in a sequence such as strings, tuple, list.

“in operator” >  This operator is used to access that whether if the value is existing in sequence or not.  It access to true if it finds that a variable in a specified sequence and false otherwise.

“not in operator” > It is accessed for true if it doesn’t find  variable in specified sequence and false otherwise.

#### Example:

Explanation: Here ‘H’ is in x but Hello is not present in x. Similarly, 1 is the key and ‘a’ is the value in dictionary y. Hence ‘a’ in y returns for False.

## Identity Operator

Identity operator is used to compare the memory location of two identity operator, objects are used.

“is operator” > It access to true if the variables mentioned  are on either side of the operator points to the same objects and results to false otherwise.

‘‘is not operator” Accesses to false if the variable if variable on either side of the operator directs to same object and results to true otherwise.

#### Example:

Explanation: Here, we see that x1 and y1 are integers of same values, so they are equal as well as identical. Same case with x2 and y2 (strings). But in case of x3 and y3 they are list. They are equal but not identical. Since lists are mutable (which can be change), interpreter locates them separately in memory although they are equal.

### Difference between == and is operator:

Equal to equal operator compares the values of the opponent and check for the value equality whereas is operator checks whether both the opponents refers to same object or not.

## Bitwise Operator

Bitwise operates acts on as if are string on binary digits. It operates bit by bit as name suggests. It inverts all bits of its operand. It always works with integer values. It will convert digital values into binary.

AND: Bits which are set in both x and y and resulted as set.

OR: Bits that are set in either x or y are sets.

XOR: Bits that are set in x or y but not both are sets.

NOT: Bits that are et in x are not set.

Shift Left: Shift the bits of x and y towards left.

Shift Right: Shift the bits of x and y towards right.

#### Examples:

• Right Shift                                                                       Left Shift

a>>3                                                                                 a<<3

a = 110 0000 1011                                                                           a = 1100 0000 1010

110 0000 0101                                                                         1000 0001 010

11 0000 0010                                                                   0000 0010 10

1 1000 0001                                                             0000 0101 0

• A =  0011 1100

b = 0000 1101

Here,

A & b = 0000 1100

A | b = 0011 1101

A ^ b = 0011 0001

~ a = 1100 0011

#### Recommended Posts: ##### Pawan Kashyap
Hi.. My name is Pawan Kashyap. I am Social Media Promotor, SEO Analyst, a professional Blogger and Website Developer. I started my Blogging Career in 2016. Blogging is my passion and profession. Read my Blog to get updated with latest news in Education, Career, and Finance.