Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
61 views
in Technique[技术] by (71.8m points)

python - How to repeat a string with spaces?

I am trying string repetition in Python.

#!/bin/python
str = 'Hello There'
print str[:5]*2

Output

HelloHello

Required Output

Hello Hello

Can anyone please point me in the right direction?

Python version: 2.6.4

question from:https://stackoverflow.com/questions/17183259/how-to-repeat-a-string-with-spaces

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
string = 'Hello There'
print ' '.join([string[:5]] * 2)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...