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