'{:02X}'
and copy it three times.str.format()
on the resulting string to replace the placeholders with the given values.def rgb_to_hex(r, g, b):
return ('{:02X}' * 3).format(r, g, b)
rgb_to_hex(255, 165, 1) # 'FFA501'
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️