python中,如何将字符串中多个空格分隔的修改为一个逗号?

2024-12-22 23:18:52
推荐回答(3个)
回答1:

string = "word 2 3 4 5 6 7"
string = ",".join(string.split())

回答2:

line = line.replace("\s",",")
(i.e. \s = \t\n)

回答3:

line = "1 2 3 4 5 6 7"
line = line.replace(" ","")
for i in list(line):
print i+",",

不是最好,没有用到python的长处,汗,基本达到要求