116

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:

---
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Hick
  • 35,524
  • 46
  • 151
  • 243

2 Answers2

222

Python 2.x:

print '-' * 3

Python 3.x:

print('-' * 3)
8

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
  • 21,584
  • 4
  • 41
  • 73