The string.replace() is deprecated on python 3.x. What is the new way of doing this?
FYI, when appending some characters to an arbitrary, position-fixed word inside the string (e.g. changing an adjective to an adverb by adding the suffix -ly), you can put the suffix at the end of the line for readability. To do this, use split()
inside replace()
:
s="The dog is large small"
ss=s.replace(s.split()[3],s.split()[3]+'ly')
ss
'The dog is largely small'
As in 2.x, use str.replace().
Example:
>>> 'Hello world'.replace('world', 'Guido')
'Hello Guido'