How to pad zeroes to a string?

前端 未结 17 2165
醉酒成梦
醉酒成梦 2020-11-21 22:59

What is a Pythonic way to pad a numeric string with zeroes to the left, i.e. so the numeric string has a specific length?

17条回答
  •  深忆病人
    2020-11-21 23:38

    Its ok too:

     h = 2
     m = 7
     s = 3
     print("%02d:%02d:%02d" % (h, m, s))
    

    so output will be: "02:07:03"

提交回复
热议问题