Python的rstrip函數不支持自定義字符。rstrip函數只能刪除字符串末尾的空格字符或者換行符等。如果想自定義刪除的字符,可以使用strip函數結合自定義字符集來實現。例如:
s = "hello world!!" custom_chars = "!" s = s.rstrip(custom_chars) print(s) # 輸出:hello world