A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/difference-between-and-is-operator-in-python/ below:

Difference between == and is operator in Python

Difference between == and is operator in Python

Last Updated : 04 Apr, 2025

In Python, == and is operators are both used for comparison but they serve different purposes. The == operator checks for equality of values which means it evaluates whether the values of two objects are the same. On the other hand, is operator checks for identity, meaning it determines whether two variables point to the same object in memory.

== Operator

To compare objects based on their values, Python's equality operators (==) are employed. It calls the left object's __eq__() class method which specifies the criteria for determining equality. However, these constraints are typically written so that the equality operator == returns True if two objects, have the same value and returns False if both have different value.

Python
x = [1, 2, 3]
y = [1, 2, 3]
z = x

# Equality comparison (==)
if x == y:
    print("True")
else:
    print("False")

Explanation:

‘is’ Operator

Python identity operators (is, is not) are used to compare objects based on their identity. When the variables on either side of an operator point at the exact same object, the "is" operator's evaluation is true. Otherwise, it would provide us with a false assessment.

Code Example of == operator and ‘is’ Operator :  Python
x = [1, 2, 3]
y = [1, 2, 3]
z = x


# Case 1: Identity comparison (is)
if x is y:
    print("True")
else:
    print("False")

# Case 2: Comparing references (is)
if x is z:
    print("True")
else:
    print("False")

Explanation:

Comparison: Parameters

is Operator

== Operator

Name The ‘is’ is known as the identity operator. The ‘==’ is known as the equality operator. Uses The is operator checks if two variables point to the same object in memory. It returns True if both variables are referring to the exact same object. If they point to different objects, even if the values are the same, it returns False. When the variables on either side have the exact same value, the == operator evaluation is true. Otherwise, it will evaluate as False.

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4