Reputation: 63
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
Upvotes: 0
Views: 344
Reputation: 1778
As an alternative you could use the regular expression module
import re
In [9]: re.sub(' ', 'x', text)
Out[9]: 'howxisxyourxdayx?'
Upvotes: 0
Reputation: 133514
>>> text = 'how is your day ?'
>>> text.replace(' ', 'x')
'howxisxyourxdayx?'
Upvotes: 0