I have a string S = 'spam'
When I use the method replace as S.replace('pa', 'xx')
S.replace('pa', 'xx')
The output I get is -
Out[1044]: "sxxm's"
Why then are the python strings known to be immutable ?
I have a string S = 'spam'
When I use the method replace as S.replace('pa', 'xx')
S.replace('pa', 'xx')
The output I get is -
Out[1044]: "sxxm's"
Why then are the python strings known to be immutable ?
S = 'spam'
S.replace('pa', 'xx')
print S
You will get the same string 'spam'
You are not saving the return value.
Snew = S.replace('pa', 'xx')
should work