在Python中,可以使用字符串的replace()方法來(lái)刪除指定的字符。
replace()
string = "Hello, World!" char = "o" new_string = string.replace(char, "") print(new_string)
輸出結(jié)果:Hell, Wrld!
Hell, Wrld!
在上面的例子中,我們使用replace()方法將字符串中的字符o替換為空字符串,從而實(shí)現(xiàn)刪除字符的效果。
o
億速云公眾號(hào)
手機(jī)網(wǎng)站二維碼
Copyright ? Yisu Cloud Ltd. All Rights Reserved. 2018 版權(quán)所有
廣州億速云計(jì)算有限公司粵ICP備17096448號(hào)-1 粵公網(wǎng)安備 44010402001142號(hào)增值電信業(yè)務(wù)經(jīng)營(yíng)許可證編號(hào):B1-20181529