Dec-06-2018, 12:14 PM
(This post was last modified: Dec-06-2018, 12:16 PM by Gribouillis.)
When you run the code in the interactive interpreter, each statement is compiled separately. On each of the two assignment statements, python creates a int instance, so there are two instances.
If you run the code from the file, all the statements are compiled together and I guess python is smart enough to detect that it only needs to create a single int instance for the two literal constants 500. You could have more information by examining bytecode with the help of the dis module.
If you run the code from the file, all the statements are compiled together and I guess python is smart enough to detect that it only needs to create a single int instance for the two literal constants 500. You could have more information by examining bytecode with the help of the dis module.