标签: python string
我想以优雅的方式做到这一点:
>>> ''.zfill(5, '-') '-----'
有没有办法用填充字符和计数器初始化字符串? 当然,计数可能会有所不同。
答案 0 :(得分:11)
试试吧:
>>> '-'*5 '-----'
在Python中就是这么简单:)
答案 1 :(得分:1)
introduction to strings in the "official" tutorial说:
字符串可以连接(粘合 与+运算符一起使用 重复*
+
*