-5

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.

m0nhawk
  • 22,980
  • 9
  • 45
  • 73
Linnie
  • 5
  • 1
  • 2

1 Answers1

0

Just use replace:

>>> text = raw_input('Enter text: ')
Enter text: iphone 7 black
>>> text.replace(' ', '+')
'iphone+7+black'
lch
  • 2,028
  • 2
  • 25
  • 46
  • Thank you so much - that worked perfectly! Sorry for asking such a dumb question - I'm just working on my first ever coding project and am not familiar with a lot of the basic functions that are out there. – Linnie Apr 17 '17 at 16:00
  • Don't worry! Jut confirm and upvote the answer if it was useful! – lch Apr 17 '17 at 16:01