We know that the "is" operator compares the id of two objects. But why it happens:
1.
x = [1, 2, 3]
y = [1, 2, 3]
print(x is y)
x = (1, 2, 3)
y = (1, 2, 3)
print(x is y)
Run it as python test.py, the output is:
False
True
Run it in Python interpreter:
>>> x = (1, 2, 3)
>>> y = (1, 2, 3)
>>> x is y
False
x = (1, [2], 3)
y = (1, [2], 3)
print(x is y)
Run it as python test.py, the output is:
False
How Python compare id of objects of different types ?