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

Dewsworld picture Dewsworld · Feb 26, 2012 · Viewed 462.1k times · Source

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

Answer

Ignacio Vazquez-Abrams picture Ignacio Vazquez-Abrams · Feb 26, 2012

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

Example:

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