On this page
  1. hex
  2. Import & Availability
  3. Overview & Signature
  4. Usage
  5. Gotchas
  6. REPL Inspect

hex

Prev: help | Up: __builtins__ | Next: id
Rel: ascii, bin, chr, format, oct
Ref: docs.python.org — hex
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import hex

Overview & Signature

hex(number, /)

Return the hexadecimal representation of an integer.

Usage

assert hex(255) == "0xff"
assert hex(-16) == "-0x10"
assert f"{255:04x}" == "00ff"   # bare zero-padded lowercase hex

Gotchas

REPL Inspect

help(hex)

Linked from

Related notes