News for hackers. Stuff that matters.
Re:Python strings are immutable, but only sometimes by mark-r on Monday February 15, 2021 @09:48PM (#26150378)
The "numbers less than 256 are the same objects" wasn't done so you could use "is" on them, that's just a side effect. It was done as an optimization, because those small integers are far more common than the larger ones. You save space, because you need only one copy of those small integers. And you save time, because those objects are never destroyed or recreated.
Re:Python strings are immutable, but only sometimes by orf on Tuesday February 16, 2021 @01:32AM (#26151502)
Yes, of course, But I never said that it was done so you could use “is” with them, only that “is” is the wrong thing to do on them.
Re:Python strings are immutable, but only sometimes by roelschroeven on Tuesday February 16, 2021 @06:38AM (#26153005)
Of course. "is" is almost always the wrong thing to do.