# Python Identity Operators

**Python | Identity operators**: Here, we are going to learn about the various identity operators in Python with their usages, syntaxes, and examples.

Submitted by **IncludeHelp**, on May 31, 2020

Identity operators are used to perform the comparison operation on the objects i.e. these operators check whether both operands refer to the same objects (with the same memory location) or not.

Following are the identity operators,

Operator | Descriptions | Example |
---|---|---|

is |
It returns True if both operands refer to the same objects; False, otherwise. | x is y |

is not |
It returns True if both operands do not refer to the same objects; False, otherwise. | x is not y |

**Syntax:**

operand1 is operand2 operand1 is not operand2

## Python 'is' operator example

# Python program to demonstrate the # example of identity operators x = [10, 20, 30] y = [10, 20, 30] z = x # Comparing the values using == operator print("x == y: ", x == y) print("y == z: ", y == z) print("z == x: ", z == x) print() # Comparing the objects # whether they are referring # the same objects or not print("x is y: ", x is y) print("y is z: ", y is z) print("z is x: ", z is x) print()

**Output:**

x == y: True y == z: True z == x: True x is y: False y is z: False z is x: True

## Python 'is not' operator example

# Python program to demonstrate the # example of identity operators x = [10, 20, 30] y = [10, 20, 30] z = x # Comparing the values # using != operator print("x != y: ", x != y) print("y != z: ", y != z) print("z != x: ", z != x) print() # Comparing the objects # whether they are referring # the same objects or not print("x is not y: ", x is not y) print("y is not z: ", y is not z) print("z is not x: ", z is not x) print()

**Output:**

x != y: False y != z: False z != x: False x is not y: True y is not z: True z is not x: False

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.