gpt4 book ai didi

python - 如何从字符串中删除所有尾随破折号?

转载 作者:太空宇宙 更新时间:2023-11-04 07:12:27 25 4
gpt4 key购买 nike

例子:

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

>> print doSomething(string1)
>> title

>> print doSomething(string2)
>> title

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

最佳答案

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

关于python - 如何从字符串中删除所有尾随破折号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4414838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com