a = "This is the island of istanbul"
print (a.replace("is" , "was" , 3))
#3 is the maximum replacement that can be done in the string#
>>> Thwas was the wasland of istanbul
# Last substring 'is' in istanbul is not replaced by was because maximum of 3 has already been reached
在2.x中,使用^{} 。
示例:
还要注意,点绑定比字符串连接强,即使用括号:('Hello'+'world').replace('world','Guido')
python 3中的replace()方法仅用于:
replace()
是Python3中<class 'str'>
的一种方法:相关问题 更多 >
编程相关推荐