How can two Python objects have same id but ‘is’ operator returns False?

In the first example, your objects don’t overlap in time: one is created then destroyed, then another is created with the same id.

When you compare them with is, you are holding onto both objects, so they get different ids.

Leave a Comment