亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

在Python中操作字符串之replace()方法的使用

 更新時間:2015年05月19日 15:19:35   投稿:goldensun  
這篇文章主要介紹了在Python中操作字符串之replace()方法的使用,是Python入門中的基礎(chǔ)知識,需要的朋友可以參考下

 replace()方法返回當(dāng)前old換成new,可選擇的替代限制到最大數(shù)量的字符串的副本。
語法

以下是replace()方法的語法:

str.replace(old, new[, max])

參數(shù)

  •     old -- 這是要進(jìn)行更換的舊子串。
  •     new -- 這是新的子串,將取代舊的子字符串。
  •     max -- 如果這個可選參數(shù)max值給出,僅第一計數(shù)出現(xiàn)被替換。

返回值

此方法返回字符串的拷貝與舊子串出現(xiàn)的所有被新的所取代。如果可選參數(shù)最大值給定,只有第一個計數(shù)發(fā)生替換。
例子

下面的示例演示了replace()方法的使用。

#!/usr/bin/python

str = "this is string example....wow!!! this is really string";
print str.replace("is", "was");
print str.replace("is", "was", 3);

當(dāng)我們運行上面的程序,它會產(chǎn)生以下結(jié)果:

thwas was string example....wow!!! thwas was really string
thwas was string example....wow!!! thwas is really string

相關(guān)文章

最新評論