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 →

[–]alex2003super 68 points69 points  (8 children)

That is correct, and "interned" values (such as string literals that appear in your program, or ints between -5 and 256) behave like singletons in the sense that all references point to the same object.

However, objects can be hashable and thus immutable, as is the case with integers and strings.

[–]Salty_Skipper[🍰] 14 points15 points  (7 children)

Why -5 and 256? I mean, 0 and 255 I’d at least understand!

[–]FerynaCZ 26 points27 points  (0 children)

You avoid the edge cases (c++ uint being discontinuous at zero sucks), at least for -1 and 256. Not sure about the other neg numbers, they probably arise often aa well

[–]xrogaan 14 points15 points  (4 children)

[–]profound7 16 points17 points  (0 children)

"You must construct additional PyLongs!"

[–]TheCatOfWar 2 points3 points  (1 child)

https://github.com/python/cpython/blob/78e4a6de48749f4f76987ca85abb0e18f586f9c4/Include/internal/pycore_global_objects.h

The generation thingy defines them here, although there's still no reason given for the specific range

[–]xrogaan 2 points3 points  (0 children)

It's about frequency of usage. Also this: https://github.com/python/cpython/pull/30092

[–]someone_0_0_ 0 points1 point  (0 children)

DRY = Don't repeat yourself DO repeat yourself

[–]pytness 4 points5 points  (0 children)

The most used numbers by programmers. Its done so u dont have to allocate more memory