Skip to content Skip to sidebar Skip to footer

Re-formatting User Input With Spaces

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.

Solution 1:

Just use replace:

>>> text = raw_input('Enter text: ')
Enter text: iphone 7 black
>>> text.replace(' ', '+')
'iphone+7+black'

Post a Comment for "Re-formatting User Input With Spaces"