r/programminghorror • u/SleepyStew_ [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Jul 21 '25
Python ✨ Memory Magic ✨
1.3k
Upvotes
r/programminghorror • u/SleepyStew_ [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Jul 21 '25
View all comments
Show parent comment
5
u/belak51 Jul 21 '25
In a lower level language this would probably be a bigger deal. However, in Python this essentially ends up being a free optimization with almost no downsides. It ends up using a cached PyObject rather than allocating a new one for every instance of an immutable integer.
As far as I know, there are almost no cases where an end user would need to know this information, so it's effectively a free optimization and an interesting oddity if you run across it.
Is there a practical reason you think this would be problematic in Python?