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
212 views
in Technique[技术] by (71.8m points)

Python repeat string

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/python-repeat-string

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
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

...