Python 2.7: replace string object method with obsolete

My "workmates" simply told me that the method of replacing a string object was deprecated and would be deleted at 3.xx.

May I ask you if this is true, why, and if so, how to replace it (with examples)?

Many thanks.

+5
source share
2 answers

the documentation in 3.2 says nothing that the replace method of type str should be removed. I also see no reason why anyone should do this.

What has been removed is the replace function in the string module .

Example:

"bla".replace("a", "b")

calls the replace method of type str.

string.replace("bla", "a", "b")

calls the string module replacement function.

, , . - Python. , Python 2.0 (!). Python, , , , - .

+19

http://docs.python.org/library/string.html#deprecated-string-functions, . .

. :

s = 'test'
string.replace(s, 'est', '')

s.replace('est', '')
+5

All Articles