Setting fixed length with python

前端 未结 5 1315
遇见更好的自我
遇见更好的自我 2021-01-05 02:19

I have str that are like \'60\' or \'100\'. I need the str to be \'00060\' and \'00100\',

How can i do this? code is something like this: I was using \'0\'+\'0\'+

5条回答
  •  自闭症患者
    2021-01-05 02:35

    Since you are manipulating strings, str.zfill() does exactly what you want.

    >>> s1, s2 = '60', '100'
    >>> print s1.zfill(5), s2.zfill(5)
    00060 00100
    

提交回复
热议问题