开发者

Create python string with fill char and counter

开发者 https://www.devze.com 2023-03-08 20:48 出处:网络
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?

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

精彩评论

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