Take the 2-minute tour ×

I want to print a character or string like '-' n number of times.

Can I do it without using a loop?.. Is there a function like


..which would mean printing the - 3 times, like this:

share|improve this question

1 Answer 1

up vote 48 down vote accepted

Python 2.x:

print '-' * 3

Python 3.x:

print('-' * 3)
share|improve this answer
Possibly the shortest correct answer on Stack Overflow :P –  dbr Jun 8 '09 at 1:21
And bought me just enough rep to retag the question as beginner... –  John Pirie Jun 8 '09 at 1:36
If the OP is using Python 3, it's print('-'*3) –  RexE Jun 8 '09 at 3:41
This is mentioned in the Built-in Types section of the docs (and should be mentioned in the official tutorial) docs.python.org/library/… –  dbr Jun 9 '09 at 3:17
this is the correct bookmark in the docs: docs.python.org/2/library/… –  George Birbilis Sep 13 at 22:28

Your Answer


