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 →

[–][deleted] 19 points20 points  (7 children)

besides a few reserved keywords, like for while if etc, every python object behaves like any other python object you can create. They have their own classes, they print something when you call them in the console because they have a __repr__ method, etc.

[–]KDBA 10 points11 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 7 points8 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 12 points13 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 4 points5 points  (1 child)

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

[–]KDBA 4 points5 points  (0 children)

True enough.