DS301222 #Quiz 2 Operators in Python Review


why this is wrong? pls explain…
i also run this code in VS code, there it is showing True.

2 Likes

2 Likes

@vaishu.swap10112016

Please refer this

In the code , the “is” operator is used to check whether two variables refer to the same object in memory. In this case, even though the values of the tuples “a” and “b” are the same, they are two distinct objects in memory.

Therefore, the expression “a is b” will evaluate to False because “a” and “b” are two different tuples with the same values, so they are not the same object in memory.

If you want to check whether the values of two tuples are the same, you can use the “==” operator instead, like this:

a = (1, 2, 3)
b = (1, 2, 3)
print(a == b) # This will output True

This will compare the values of the two tuples, and return True if they have the same values in the same order.