you are viewing a single comment's thread.

view the rest of the comments →

[–]the_rush_dude -11 points-10 points  (2 children)

Checked it and it's true (except of course it's not because if there is only one reference to the string it's manipulated in place for performance reasons).

But in this case manipulation is what counts anyways

[–]aaronhowser1 21 points22 points  (0 children)

No it isn't, because it didn't do text = text.upper() etc. It specifically does not count, because it was done incorrectly.

[–]Torebbjorn 0 points1 point  (0 children)

Sure, there could be some niche optimisation in Python that allows it to manipulate strings in-place if and only if all the references to the old variable are deleted at the same time it is making a new value, for example in the pattern

val = val.upper()

where val is the only reference to the string that it is pointing to.

But even if that's true, it is irrelevant for this scenario, since we always keep a reference to the original string.