109

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:

---
Georgy
  • 9,972
  • 7
  • 57
  • 66
Hick
  • 33,822
  • 46
  • 145
  • 240

2 Answers2

211

Python 2.x:

print '-' * 3

Python 3.x:

print('-' * 3)
7

The accepted answer is short and sweet, but here is an alternate syntax allowing to provide a separator in Python 3.x.

print(*3*('-',), sep='_')
Olivier Melançon
  • 20,340
  • 3
  • 37
  • 69