Create a python string with char padding and counter

I would like to do it elegantly:

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

Is there a way to initialize a string with char padding and a counter? Of course, the count may vary.

+3
source share
2 answers

Just try:

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

This is simple in Python :)

+11
source

the introduction to the lines in the official textbook reads:

Rows can be combined (glued together) with the operator +and repeated with*

+1
source

All Articles