0

I understand that the "is" operator checks identity between two objects, but what is this?

a=25
b=25
a is b
True

Why is this true if

a = [1,2,3]
b = [1,2,3]
a is b
False

And from this post, https://www.quora.com/Python-is-operator, it says all immutable objects, like integers from the first example, will have the first example's result, True, but tuples are immutable and this happens:

a = (1,2)
b = (1,2)
a is b
False

Can someone explain please?

Thanks.

Julien
  • 13,986
  • 5
  • 29
  • 53
Art
  • 275
  • 2
  • 9
  • This is duplicate of https://stackoverflow.com/questions/38189660/two-variables-in-python-have-same-id-but-not-lists-or-tuples – Sharad Oct 31 '17 at 05:53
  • In summary, python does this for memory optimization (when it can). – Sharad Oct 31 '17 at 05:54

0 Answers0