Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create python string with fill char and counter

Tags:

python

string

I'd like to do it in an elegant fashion:

>>> ''.zfill(5, '-')
'-----'

There's any way to initialize a string with a fill char and a counter? Of course, count may vary.

like image 787
Caruccio Avatar asked May 25 '11 23:05

Caruccio


1 Answers

Just try:

>>> '-'*5
'-----'

It's that simple in Python :)

like image 154
berni Avatar answered Oct 27 '22 22:10

berni