“{0:0>3}”.format(1) ‘001’ >>> “{0:0>3}”.format(10) ‘010’ >>> “{0:0>3}”.format(100) ‘100’
说明:
{0 : 0 > 3}
│ │ │ │
│ │ │ └─ Width of 3
│ │ └─ Align Right
│ └─ Fill with '0'
└─ Element index
Python使用str.format添加前导零
“{0:0>3}”.format(1) ‘001’ >>> “{0:0>3}”.format(10) ‘010’ >>> “{0:0>3}”.format(100) ‘100’
说明:
{0 : 0 > 3}
│ │ │ │
│ │ │ └─ Width of 3
│ │ └─ Align Right
│ └─ Fill with '0'
└─ Element index