[python]问题:python如何将字符串最后一个“,”给删掉

可以使用字符串的rstrip()方法或者切片操作来实现。这里有两种方法:

方法1:使用rstrip()方法

s = "hello, world,"
s = s.rstrip(",")
print(s)

方法2:使用切片操作

s = "hello, world,"
if s[-1] 

猜你喜欢

转载自blog.csdn.net/Chaorewq/article/details/132510227