Using %02d instead of %02s


Why do we use %02d instead of %02s for the date? Does the s stand for string and d for date?

You get the same result when run in the program.

Why did the video use %s over %d

The d stands for digit, and is the same as i for the most part.


The 02 applies to output size, I believe.


is str type.

All output is string but the symbols indicate the type of content being inserted.

print ("%d" % 42)          # 42

print (type("%d" % 42))    # <class 'str'>


decimal as opposed to octal or hexadecimal or binary


Thinking ‘decimal’ and writing ‘digit’, d’oh!


would %02i give me the same result? I have not learned what %i would do.


Yes, %i will behave the same as %d.

>>> print ("%02d" % 4)
>>> print ("%02i" % 4)

Note how the 02 pads the lead with a zero when the digit is singular.


Formatted Output


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