python3将数字转换为6位字符串(补0)
num = 233
str_num = str(num) # 数字转化为字符串
str_six_num = str_num.zfill(6) # 字符串右对齐补0
结果:
000233
zfill() 方法返回指定长度的字符串,原字符串右对齐,前面填充0
用法:
str.zfill(width)
num = 233
str_num = str(num) # 数字转化为字符串
str_six_num = str_num.zfill(6) # 字符串右对齐补0
结果:
000233
zfill() 方法返回指定长度的字符串,原字符串右对齐,前面填充0
用法:
str.zfill(width)