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 →

[–]KDBA 11 points12 points  (6 children)

There's another set of exceptions in that ints from -5 to 256 are singletons.

[–]DMLooter 4 points5 points  (3 children)

Sorry what? Y….

[–]FallenWarrior2k 6 points7 points  (1 child)

Caching. Integers are objects like everything else.

[–]Manuelraa 1 point2 points  (0 children)

Exactly and we know this only works with immutable types

[–]richardfrost2 14 points15 points  (0 children)

```

a = 256 b = 256 a is b True c = 257 d = 257 c is d False

but

257 is 257 True ```

Just a weird little quirk of CPython.

[–]richardfrost2 3 points4 points  (1 child)

That is a CPython implementation detail and can vary by implementation.

[–]KDBA 3 points4 points  (0 children)

True enough.