Python strings are immutable, but only sometimes

Update 2/16/2021: See the discussion of this post on Hacker News.

The standard wisdom is that Python strings are immutable. You can’t change a string’s value, only the reference to the string. Like so:

x = "hello"
x = "goodbye"  # New string!

Which implies that each time you make a change to a string variable, you are actually producing a brand new string. Because of this, tutorials out there warn you to avoid string concatenation inside a loop and advise using join instead for performance reasons. Even the official documentation says so!

This is wrong. Sort of.

Continue Reading

Information shared by : PALGUNI G T