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
.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Just use replace
:
>>> text = raw_input('Enter text: ')
Enter text: iphone 7 black
>>> text.replace(' ', '+')
'iphone+7+black'