我怎样才能删除python中的字符串的最后一个字符?
这个问题在这里已经有了答案:
正如你所说,你不需要为此使用正则表达式。 你可以使用rstrip 。
my_file_path = my_file_path.rstrip('/')
如果最后有多个/ ,则会将其全部删除,例如'/file.jpg//' - > '/file.jpg' 。 从你的问题来看,我认为这样可以。
最简单的是
正如@greggo指出的那样
string="mystring";
string[:-1]
你可以使用String.rstrip 。
result = string.rstrip('/')
链接地址: http://www.djcxy.com/p/55111.html
上一篇: How can I remove the last character of a string in python?
