tags:

views:

590

answers:

1

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

print('-',3)

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

---
+12  A: 

print '-' * 3

John Pirie
Possibly the shortest correct answer on Stack Overflow :P
dbr
And bought me just enough rep to retag the question as beginner...
John Pirie
If the OP is using Python 3, it's print('-'*3)
RexE
This is mentioned in the Built-in Types section of the docs (and should be mentioned in the official tutorial) http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange
dbr