How to increment a value with leading zeroes?

后端 未结 7 1558
一整个雨季
一整个雨季 2021-02-05 22:23

What would be the best way to increment a value that contains leading zeroes? For example, I\'d like to increment \"00000001\". However, it should be noted that the number of

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 22:51

    "%%0%ii" % len(x) % (int(x)+1)

    -- MarkusQ

    P.S. For x = "0000034" it unfolds like so:

    "%%0%ii" % len("0000034") % (int("0000034")+1)
    "%%0%ii" % 7 % (34+1)
    "%07i" % 35
    "0000035"
    

提交回复
热议问题