输入
str = 'test1,test2,test3,'
输出
str = 'test1,test2,test3'
要求去掉最后出现的 ','
最佳答案
只需使用 rstrip() .
result = your_string.rstrip(',')
关于python - 去除最后一个逗号的字符串函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12625636/