python- string processing - filling completion string of fixed length (s 0) of the three methods

'' '
Original string left aligned, right zero padded:
' ''
str.ljust (width, '0')
INPUT: '789'.ljust (32,' 0 ')
Output:' 78900000000000000000000000000000 '

'' '
Original string right justified, zero-extension:
Method a: '
''
str.rjust (width, '0')
INPUT: '798'.rjust (32,' 0 ')
Output:' 00000000000000000000000000000798 '
'' '
method two: '
''
str.zfill (width)
INPUT: '123'.zfill (32)
Output:' 00000000000000000000000000000123 '
' ''
method three:
'' '
'% 07D '% n-
INPUT:'% 032d '89%
Output:' 00000000000000000000000000000089 '

Guess you like

Origin www.cnblogs.com/sunxiuwen/p/11521368.html