Python Object Comparison : "is" vs "==" Last Updated : 26 Feb, 2025 Comments Improve Suggest changes 5 Likes Like Report In Python, both is and == are used for comparison, but they serve different purposes:== (Equality Operator) → Compares values of two objects.is (Identity Operator) → Compares memory location of two objects. Python a = [1,2,3] b = [1,2,3] print(a == b) print(a is b) OutputTrue False Explanation: a and b are separate list objects with identical values [1, 2, 3]. == checks value equality and returns True, while is checks memory identity and returns False.'is' operator The is operator checks if two variables refer to the same object in memory, rather than just having equal values. It returns True only if both variables point to the exact same object in memory.Example: Python x = [10, 20, 30] y = x # y points to the same memory location as x print(x is y) OutputTrue Explanation:y is assigned x, meaning both x and y now reference the same object in memory.x is y returns True because x and y share the same identity.== operatorThe == operator checks if two objects contain the same values, regardless of whether they are stored in the same memory location.Example: Python a = [1, 2, 3] b = [1, 2, 3] print(a == b) # same values OutputTrue Explanation:a and b are both lists containing [1, 2, 3], but they are separate objects in memory.a == b returns True because their values are the same.is vs == Summary TableParameter== operatoris operatorNameEquality operatorIdentity operatorFunctionalityChecks if values of two objects are equal.Checks if memory addresses of two objects are the same.Use CaseUsed when we want to compare data stored in objects.Used when we want to check whether two variables point to the same object in memory.Mutable Objects (lists, dicts, sets, etc.)Returns True if contents are the same, even if they are different objects.Returns False unless both variables point to the same memory location.Immutable Objects (ints, strings, tuples, etc.)Returns True if values are equal.May return True due to Python's internal object caching (interning).Example 1[1,2,3] == [1,2,3] → True[1,2,3] is [1,2,3] → FalseExample 2"hello" == "hello" → True"hello" is "hello" → True Create Quiz Comment S Sabya_Samadder Follow 5 Improve S Sabya_Samadder Follow 5 Improve Article Tags : Misc Python Python-Operators python-basics Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like