6. Identity Operators

Identity operators are used to compare the memory locations of two objects.

In Python, every object has a unique memory address (called identity), and these operators check whether two variables point to the same object in memory.

Types of Identity Operators:

There are 2 types of Identity Operators in Python:
  • is
  • is not

List of Identity Operators

Operator Name Description
is Identity Operator Returns True if both variables refer to the same object (memory).
is not Negative Identity Returns True if both variables do not refer to the same object.

Types of Identity Operators:

  1. Identity Operator (is)

    is checks if two variables refer to the same object in memory.

    a = [1, 2]  
    b = a  
    print(a is b)  # True

    Output: True

    Explanation:

    Both a and b point to the same list in memory. Hence, a is b returns True.

  2. Negative Identity Operator (is not):

    is not returns True if two variables do not refer to the same object.

    x = [10, 20]  
    y = [10, 20]  
    print(x is not y)   # True

    Output: True

    Explanation:

    Even though x and y have the same values, they are stored at different memory locations. So, x is not y returns True.

Why Use Identity Operators?

They are useful when we want to:

  • Check if two variables refer to the same object (not just same value).
  • Differentiate between is and == (value vs identity).
  • Understand reference handling in Python objects.

Example:

a = [1, 2, 3]
b = a
c = [1, 2, 3]

print(a is b)       # True
print(a is c)       # False
print(a == c)       # True

Explanation:

  • a is bTrue because both refer to the same list in memory.
  • a is cFalse because c is a different list, even though the values are same.
  • a == cTrue because both have equal contents (value-wise).

Note: is compares identities (memory address), while == compares values.

Where it is Used?

  • To check if two variables point to the same object
  • In memory management and object referencing
  • Useful in conditions where identity check is more important than value

Summary

  • is: True if both refer to same object in memory
  • is not: True if both refer to different objects
  • ==: Compares values
  • Identity ≠ Value

Welcome to ShikshaSanchar!

ShikshaSanchar is a simple and helpful learning platform made for students who feel stressed by exams, assignments, or confusing topics. Here, you can study with clarity and confidence.

Here, learning is made simple. Notes are written in easy English, filled with clear theory, code examples, outputs, and real-life explanations — designed especially for students like you who want to understand, not just memorize.

Whether you’re from school, college, or someone learning out of curiosity — this site is for you. We’re here to help you in your exams, daily studies, and even to build a strong base for your future.

Each note on this platform is carefully prepared to suit all levels — beginner to advanced. You’ll find topics explained step by step, just like a good teacher would do in class. And the best part? You can study at your pace, anytime, anywhere.

Happy Learning! – Team ShikshaSanchar