Python · August 31, 2022 0

%02d – python

In python, %d is similar to %s, but uses numbers instead of strings. This prevents typing str() continuously.

The %02d could be useful in creating leading 0s. This could be used in digital clocks that need to always have 4 digits.

Example:

print("%02d %02d" % (4, 1))

Output:

04 01

Example:

print("%02d %010d" % (4, 1))

Output:

04 0000000001