Get Hex triplet for color and real 256 RGB from diffuse Color using python as you know the RGB structure each parameter (red, green, and blue) defines the intensity of the color as an integer between 0 and 255., Actually, in Blender, you have that  in sRGB, then any  traditional convertion to HEX work BECAUSE the Hex in blender is GAMMA CORRECTED.
also in Documentation I can NOT get any reference about how get the HEX TRIPLE FOR COLOR CODE ...


how to get both with python?
UPDATE:
I want the hex value or how convert the hex to RGB
AS @dr.Sybren  I thougth That was just a straight conversion of the bytes in RGB order converted to hexadecimal notation, and then tried some simple code as @tet_ii
context = bpy.context
obj = context.object

color_inferior= obj.material_slots['inferior'].material.diffuse_color


a = '#%02x%02x%02x' % (int(255.999 * pow(color_inferior.r, 1/2.2)),int(255.999 * pow(color_inferior.g, 1/2.2)),int(255.999 * pow(color_inferior.b, 1/2.2)))    

print(a)

testing the code I got:

also, I test other codes with the same or worst result:
https://stackoverflow.com/questions/3380726/converting-a-rgb-color-tuple-to-a-six-digit-code-in-python
then. Can I capture the value directly from blender without any convertion? or do a 100% accurate conversion?
This code adapted from devtalk.blender.org, convert color from blender standard active material to hex.

import bpy

#code by : brecht - devtalk.blender.org
def to_hex(c):
    if c &lt; 0.0031308:
        srgb = 0.0 if c &lt; 0.0 else c * 12.92
    else:
        srgb = 1.055 * math.pow(c, 1.0 / 2.4) - 0.055

    return hex(max(min(int(srgb * 255 + 0.5), 255), 0))

def toHex(r,g,b):
    rgb = [r,g,b]
    result = ""
    i=0
    while i &lt; 3:
        val = str(to_hex(rgb[i]))
        val = val[2:]
        if len(val) == 1:
            val += val
        result+=val
        i+=1
    return result

ob = bpy.context.object
color_inferior = ob.active_material.diffuse_color

a = toHex(color_inferior[0],color_inferior[1],color_inferior[2])

print (a)