1

I use Python3.

{1,2} == {1,2} returns True, but {1,2} is {1,2} returns false. It seems reasonable as id({1,2}) is different from another id({1,2}).

However why id({1,2}) == id({2,1}) returns true? Even id({1,2}) == id({2,1,3}) returns true.

prosseek
  • 182,215
  • 215
  • 566
  • 871
  • 2
    `{2,1,3}` gets created, its id is fetched, then it gets garbage collected. `{1,2}` is then created and the same id is assigned to the new object. If you held on to references this wouldn't happen. – Steven Rumbalski Sep 16 '18 at 01:48
  • You should post this as an answer @StevenRumbalski – Reblochon Masque Sep 16 '18 at 01:52
  • Another candidate for duplicate [Unnamed Python objects have the same id](https://stackoverflow.com/questions/24802740/unnamed-python-objects-have-the-same-id). – Steven Rumbalski Sep 16 '18 at 02:03

0 Answers0