python给数字前面自动补0的常用2种方法 zfill方法,针对于字符串 n='123' s=n.zfill(5) print(s) 输出: “%03d”%sum,表示不足位数,前面就补0 sum=2 print("%0