Using String Replace in Python 3.x
In Python 2.x, str.replace() was a method of the string class. However, in Python 3.x, this method has been deprecated. So, what is the new way of performing string replacements in Python 3.x?
The answer is simply to use the replace() method of the str class.
For example:
>>> 'Hello world'.replace('world', 'Guido') 'Hello Guido'
As you can see, the syntax and functionality of the replace() method in Python 3.x is the same as it was in Python 2.x. The only difference is that it is now a method of the str class rather than a separate function.
The above is the detailed content of How Does String Replacement Work in Python 3.x?. For more information, please follow other related articles on the PHP Chinese website!