2

I was learning about python tuples when I encountered a weird inconsistency. This code:

x = (1,2)
y = (1,2)
print(x is y)

This gives False in shell but True in IDLE. Is there a reason for that?

1 Answers1

-3

Actually Python IDLE and shell uses different storage system for data types like tuple-() All other data types like :

  • list
  • set
  • dict

are goning to show the same.

EpicPy
  • 76
  • 1
  • 9
  • @Kral `is` and `==` are different. – EpicPy Mar 10 '21 at 05:43
  • 1
    "Actually Python IDLE and shell uses different storage system for data types like tuple" no, that is absolutely not true. – juanpa.arrivillaga Mar 10 '21 at 06:13
  • Ok then why please tell – EpicPy Mar 10 '21 at 06:17
  • There are many possible reasons, idle may be executing the whole block, where the peep-hole optimizer has optimized an immutable literal into being the same object, whereas in the shell, the blocks are separated, so the optimization doesn't happen. There are no "different storage systems" for specific data types in Python IDLE, that doesn't make any sense, IDLE is just an IDE, it isn't a separate runtime. – juanpa.arrivillaga Mar 10 '21 at 06:24