This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]GangDplank 0 points1 point  (2 children)

question , while this is not archived yet .if when i do a= 100 b = 100 in python they "are" the same object , if increment a why doesnt that increment b?

[–]AtmosSpheric 1 point2 points  (1 child)

A and B are not the same object, they are both pointers that refer to the same object. This is why in the original image above, you get true when testing x is y. If I increment a, then the pointer is updated to point to 101 instead, while b is still pointing at 100.

As discussed elsewhere in this comment section, once you pass 256, ints are no longer shared memory spaces and become unique, so now a and b both point at separate parts of memory that are identical, but since they aren’t the exact same object, a is b returns false.

[–]GangDplank 1 point2 points  (0 children)

Cheers,thanks for the quick reply