Python之字符串分段组合及split()方法

字符串的分段组合问题

问题:

用户输入一个字符串s,以字符减号(+)分割s,将其中的首尾段用加号(-)组合输出

如表输入输出:
输入 输出
Learning+python+is+a+great+choice Leaning-choice
1+2+3+4+5+6+7+8 1-8
s = input();
str = s.split("+")
print("{}-{}".format(str[0],str[-1]))

涉及知识点:split()方法,format()方法

发布了41 篇原创文章 · 获赞 49 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/wls666/article/details/89059669