溫馨提示×

python替換用什么函數

九三
295
2021-01-22 10:16:03
欄目: 編程語言

python替換用什么函數

python中使用replace函數進行替換,具體方法如下:

replace:replace()函數的作用是把字符串中的old替換成 new。

replace()函數語法:

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

參數:

old:將被替換的子字符串。

new:新字符串,用于替換old子字符串。

max:可選字符串, 替換不超過max次。

replace()函數使用方法:

str = "this is string example....wow!!! this is really string";

print str.replace("is", "was");

print str.replace("is", "was", 3);

輸出結果為:

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

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

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女