Python Object Comparison : "is" vs "==" Last Updated : 26 Feb, 2025 Summarize Suggest changes Share Like Article 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 Advertise with us Next Article Python | Decimal compare() method S Sabya_Samadder Follow Similar Reads Comparison Operators in Python Python operators can be used with various data types, including numbers, strings, boolean and more. In Python, comparison operators are used to compare the values of two operands (elements being compared). When comparing strings, the comparison is based on the alphabetical order of their characters 4 min read String Comparison in Python Python supports several operators for string comparison, including ==, !=, <, <=, >, and >=. These operators allow for both equality and lexicographical (alphabetical order) comparisons, which is useful when sorting or arranging strings.Letâs start with a simple example to illustrate the 3 min read Chaining comparison operators in Python Checking multiple conditions in a single expression is common in programming. In Python, comparison operator chaining allows us to write cleaner, more readable code when evaluating multiple conditions. Instead of using multiple and conditions, Python enables chaining comparisons directly in a mathem 4 min read Python | sympy.compare() method With the help of sympy.compare() method, we can compare the variables and it will return 3 values i.e -1 for smaller, 0 for equal and 1 for greater by using sympy.compare() method. Syntax : sympy.compare() Return : Return the value of comparison i.e -1, 0, 1. Example #1 : In this example we can see 1 min read Python | Decimal compare() method Decimal#compare() : compare() is a Decimal class method which compares the two Decimal values. Syntax: Decimal.compare() Parameter: Decimal values Return: 1 - if a > b -1 - if a < b 0 - if a = b Code #1 : Example for compare() method Python3 # Python Program explaining # compare() method # loa 2 min read Python | Decimal is_zero() method Decimal#is_zero() : is_zero() is a Decimal class method which checks whether the Decimal value is zero value. Syntax: Decimal.is_zero() Parameter: Decimal values Return: true - if the Decimal value is zero value; otherwise false Code #1 : Example for is_zero() method Python3 # Python Program explain 2 min read Article Tags : Misc Python Python-Operators python-basics Practice Tags : Miscpythonpython-operators Like