开发者

How to add space [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_如何学Go Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜