开发者

Create python string with fill char and counter

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 开发者_Python百科a counter? Of course, count may vary.


Just try:

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

It's that simple in Python :)


The introduction to strings in the "official" tutorial says:

Strings can be concatenated (glued together) with the + operator, and repeated with *

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜