Python integer to hex string with padding
integer = 2
hex_string = '0x{:02x}'.format(integer)
See pep 3101, especially Standard Format Specifiers for more info.
For integers that might be very large:
integer = 2
hex = integer.to_bytes(((integer.bit_length() + 7) // 8),"big").hex()
The "big" refers to "big endian"... resulting in a string that is aligned visually as a human would expect.
You can then stick "0x" on the front if you want.
hex = "0x" + hex