CKTIS / Python
hex()
Escribe un entero en hexadecimal con minúsculas y prefijo 0x.
Versión: Python 3.14; repository image, production runtime not attested
Sintaxis
hex(integer, /)Escribe un entero en hexadecimal con minúsculas y prefijo 0x.
Dos f representan 15 · 16 + 15 = 255. Para −16 el signo precede a 0x10. Una anchura mínima y mayúsculas se eligen mediante format.
Se aceptan tipos con __index__.
assert hex(255) == "0xff" and hex(-16) == "-0x10"
assert format(15, "04X") == "000F" and format(0x12345, "04X") == "12345"
Ejemplos
print(hex(255))
print(hex(-16))
Resultado
0xff -0x10
Se aceptan tipos con `__index__`.