You'd use str.format:
In [1]: '{:02X}'.format(0x0F)
Out[1]: '0F'
In this context {:02X} is equivalent to {0:02X}. Preceding the colon with 0 tells Python to apply this to the first argument of str.format (0x0F in this example). 02 sets the minimum field width to 2 and
Preceding the width field by a zero ('0') character enables sign-aware
zero-padding for numeric types
X is one of the available integer presentation types:
Hex format. Outputs the number in base 16, using upper- case letters
for the digits above 9.
Both quotes are from Format Specification Mini-Language.