Python学习之replace()函数

Python提供了replace()方法,用以替换给定字符串中的子串,其基本使用语法如下:

string.replace(old_string, new_string)

其中
string:是带处理的字符串
old_string:被替换的旧字符串
new_string:替换的新字符串
replace:替换的关键字
实例:

>>> name = 'liyue'
>>> name.replace('yue','qin')
'liqin'

你可能感兴趣的:(Python)