Python 用户输入格式
Python user input formatting
当操作用户输入如 - 12345 - 在字符之间添加破折号 - 1-2-3-4-5 时,我知道我们可以 运行 类似:
print(uInp, end=' -')
然而,输出变为:1-2-3-4-5-
最后的破折号没有结果。
如何在使用 end='-' 时去掉末尾的破折号
>>> s = '12345'
>>> '-'.join(s)
'1-2-3-4-5'
>>> help(str.join)
Help on method_descriptor:
join(self, iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string.
The result is returned as a new string.
Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
当操作用户输入如 - 12345 - 在字符之间添加破折号 - 1-2-3-4-5 时,我知道我们可以 运行 类似:
print(uInp, end=' -')
然而,输出变为:1-2-3-4-5-
最后的破折号没有结果。
如何在使用 end='-' 时去掉末尾的破折号
>>> s = '12345'
>>> '-'.join(s)
'1-2-3-4-5'
>>> help(str.join)
Help on method_descriptor:
join(self, iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string.
The result is returned as a new string.
Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'