12
我想根据int
和零生成一个字符串。而且长度应该始终为5
,不要超过那么小。Python格式将整数转换为固定长度的字符串
For example:
Consider a Integer: 1
Formatted String : 00001
Consider a Integer: 12
Formatted String : 00012
Consider a Integer: 110
Formatted String : 00110
Consider a Integer: 1111
Formatted String : 01111
Consider a Integer: 11111
Formatted String : 11111
感谢....得到它 – 2014-10-19 02:46:42
我发现这太有用: '打印“位置:{0:5D},修正标识:{1}在几秒钟内填充等待:{ 2:03d}“。格式(12,453585,89)”' 我的意思是,你可以避免填充0(在位置) – 2017-05-31 13:39:49
@RodrigoLaguna:当然,但问题明确要求填充零。:-) – 2017-05-31 15:29:05