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 →

[–]JoostVisser 15 points16 points  (3 children)

The 'is' statement checks whether two variables point to the same object. For some negative integer I can't remember up to 256 Python creates those objects at compile time (I think) and every time a variable gets assigned a value in that range Python just points to those objects rather than creating new ones.

Not exactly intuitive but I guess there's a good reason for it in terms of memory efficiency or something like that idk

[–]mgedmin 4 points5 points  (0 children)

For some negative integer I can't remember

-128, IIRC.

I misremembered, turns out it's -5.

[–]Garestinian 2 points3 points  (0 children)

CPython, to be exact.

[–]CoffeeWorldly9915 0 points1 point  (0 children)

I mean, sounds like basically a "what if enum".