用空格重新格式化用户输入 [英] Re-formatting user input with spaces
本文介绍了用空格重新格式化用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用输入函数,我想将输入中的任何空格转换为+
.因此,例如,如果用户输入iphone 7 black
,我想将其转换为iphone+7+black
.
I'm using an input function where I want to convert any spaces in the input to +
's. So for example, if the user inputs iphone 7 black
, I want to convert this to iphone+7+black
.
推荐答案
只需使用replace
:
>>> text = raw_input('Enter text: ')
Enter text: iphone 7 black
>>> text.replace(' ', '+')
'iphone+7+black'
这篇关于用空格重新格式化用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文