Im trying to Replace the spaces in a string i have with a "x" its for a function and im not sure of the best way to go about this ?
for example
how is your day ?
i would like this to be
howxisxyourxdayx?
thanks for your help
Im trying to Replace the spaces in a string i have with a "x" its for a function and im not sure of the best way to go about this ?
for example
how is your day ?
i would like this to be
howxisxyourxdayx?
thanks for your help
You can use replace()
text.replace(' ', 'x')
>>> text = 'how is your day ?'
>>> text.replace(' ', 'x')
'howxisxyourxdayx?'
As an alternative you could use the regular expression module
import re
In [9]: re.sub(' ', 'x', text)
Out[9]: 'howxisxyourxdayx?'