在Python中,可以使用字符串的replace()方法來刪除指定的字符。
replace()
string = "Hello, World!" char = "o" new_string = string.replace(char, "") print(new_string)
輸出結果:Hell, Wrld!
Hell, Wrld!
在上面的例子中,我們使用replace()方法將字符串中的字符o替換為空字符串,從而實現刪除字符的效果。
o