如何删除字符串末尾的所有破折号?

3 投票
1 回答
2226 浏览
提问于 2025-04-16 08:23

示例:

string1 = 'title--'
string2 = 'title-'
string3 = 'this-is-a-title----'

>> print doSomething(string1)
>> title

>> print doSomething(string2)
>> title

>> print doSomething(string3)
>> this-is-a-title

1 个回答

10
string1.rstrip("-")
# "title"
string2.rstrip("-")
# "title"
string3.rstrip("-")
# "title-is-a-title"

当然可以!请把你想要翻译的内容发给我,我会帮你用简单易懂的语言解释清楚。

撰写回答