Re:Python strings are immutable, but only sometimes
by cs702 on Monday February 15, 2021 @05:09PM
(#26148171)
Yes, of course.
BTW, that's not the "biggest" WTF feature; it's just my favorite. There's a long list of WTF features here:
https://github.com/satwikkansal/wtfpython
Otherwise, I agree, it's a pretty good going :-)
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.
Re:Python strings are immutable, but only sometimes
by baud147258 on Monday February 15, 2021 @09:11PM
(#26150146)
The "numbers less than 256 are the same objects" reminds me of the existence of the IntegerCache in Java, with an array storing the number from -128 to 127.
Plus if this is the biggest wtf then that's pretty good going.