Fix Python – How to use string.replace() in python 3.x

Question

Asked By – Dewsworld

The string.replace() is deprecated on python 3.x. What is the new way of doing this?

Now we will see solution for issue: How to use string.replace() in python 3.x


Answer

As in 2.x, use str.replace().

Example:

>>> 'Hello world'.replace('world', 'Guido')
'Hello Guido'

This question is answered By – Ignacio Vazquez-Abrams

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0