Python syntax


#1

need some clarification…
%02d= 2 characters or two spaces?
or can you explain exactly what the %02d or %04d function exactly does again?


#2
>>> "%02d" % 4
'04'
>>> "%04d" % 4
'0004'
>>> "%13d" % 4
'            4'
>>> 

Two character spaces with 0 padding.


#3

Thank you so to add on
“%02d” % 14
‘014’? Or ‘14’?

And
“%04d” % 206
‘0206’? Or ‘0000206’?


#4

The latter. Padding is only applied to fill voids. The numeric argument is the size of the print field.

The former.

Note that the format does not truncate the input…

>>> "%04d" % 65535
'65535'
>>> "%13d" % 444444444444444
'444444444444444'
>>> 

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.