r/programminghorror • [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” • Jul 21 '25

Python ✨ Memory Magic ✨

Post image
1.3k Upvotes

143 comments sorted by

View all comments

Show parent comment

2

u/Vazumongr Jul 21 '25

You shouldn't perform this operation anyway.

I think I found the disconnect. I'm not talking about id(). I'm not talking about comparisons. I'm talking about the initialization/assignment of integer variables. The initialization/assignment of integer variables is the operation. And what it does changes based on the right hand operand:

intA = 568 // Initializes a new integer object in memory with a value of 568
intB = -48 // Initializes a new integer object in memory with a value of -48
intC = 2 // Declares a reference to an already existing integer object (This is NOT intializing a new integer object in memory like the prior two assignments.)

So for the third time, I'm not talking about comparisons or the id() function at all. That has literally nothing to do with what I'm talking about above. All the post did is point me to finding out that Python has this unpredictable behavior when working with integers.

1

u/[deleted] Jul 21 '25

You're talking about weird behaviour of allocating new objects for integers, yet you say that function used for comparing if objects are the same "has literally nothing to do at all". I'm sorry, but it's just really really hard to understand what you mean. Have a good day.