Sep-04-2024, 01:37 PM
Strings are immutable. The
replace()
method creates a new string and leaves the original string unchanged.>>> s = "spam spam <i> spam" >>> t = s.replace("<i>", "[i]") >>> t 'spam spam [i] spam' >>> s 'spam spam <i> spam' >>>
« We can solve any problem by introducing an extra level of indirection »