How to add space [closed]
How to add space to string. example: "Hiwatsup?" or "hi,hello" return "hi hello" or "hi" "hello"
For "hi,hello"
you can just replace the "," for a whitespace:
hi = "hi,hello"
print hi.replace(",", " ")
you can also obtain a list of substrings split by a certain character:
print hi.split(',')
but what I really advise doing is looking at the documentation for str:
help(str)
Like this
s = "hi,hello"
t = s.split(',')
print ' '.join(t)
And for the other one
>>> s = "Hiwatsup?"
>>> print s[:2] + ' ' + s[2:]
Hi watsup?
Instead of printing, you can assign it to another variable too.
精彩评论