CKTIS / Python
hex()
Escreve um inteiro em hexadecimal com minúsculas e prefixo 0x.
Versão: Python 3.14; repository image, production runtime not attested
Sintaxe
hex(integer, /)Escreve um inteiro em hexadecimal com minúsculas e prefixo 0x.
Dois f representam 15 · 16 + 15 = 255. Para −16 o sinal precede 0x10. A largura mínima e as maiúsculas definem-se com format.
Aceitam-se tipos com __index__.
assert hex(255) == "0xff" and hex(-16) == "-0x10"
assert format(15, "04X") == "000F" and format(0x12345, "04X") == "12345"
Exemplos
print(hex(255))
print(hex(-16))
Resultado
0xff -0x10
Aceitam-se tipos com `__index__`.