Python 字符串 replace() 方法

အချက်အလက်

替换单词 "bananas":

txt = "I like bananas"
x = txt.replace("bananas", "apples")
print(x)

လက်ဦးစားအချက်အလက်

定义和用法

replace() 方法用另一个指定的短语替换一个指定的短语。

注释:

ပြောကြား

အပြင်းအထား.replace(oldvalue, newvalue, count)

ပါးချိန်

ပါးချိန် ဖော်ပြ
oldvalue လိုအပ်
newvalue လိုအပ်
count အချက်အလက်

အချက်အလက်

အချက်အလက်

အသုံးပြု သည့် "one" စကား

txt = "one one was a race horse, two two was one too."
x = txt.replace("one", "three")
print(x)

လက်ဦးစားအချက်အလက်

အချက်အလက်

ပြင်ဆင်သွင်း ပြီး အသုံးပြု သည့် "one" စကား

txt = "one one was a race horse, two two was one too."
x = txt.replace("one", "three", 2)
print(x)

လက်ဦးစားအချက်အလက်