如果字符串最后一个字符是逗号则去除
可以使用字符串的rstrip()方法去除字符串末尾的逗号。该方法会返回去除了指定字符的字符串。
示例代码如下:
string = "Hello, World,"
if string.endswith(","):
string = string.rstrip(",")
print(string) # 输出:Hello, World
原文地址: https://www.cveoy.top/t/topic/h1De 著作权归作者所有。请勿转载和采集!