字符串的分段組合問題
問題:
用戶輸入一個字符串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()方法
用戶輸入一個字符串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()方法
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。