On this page
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
- Includes
"0x"prefix: Usef"{n:x}"/f"{n:X}"when formatting bare hex strings.
REPL Inspect
help(hex)
Linked from
- tuts/python3/__builtins__
- tuts/python3/__builtins__/__builtins__
- tuts/python3/__builtins__/ascii
- tuts/python3/__builtins__/bin
- tuts/python3/__builtins__/chr
- tuts/python3/__builtins__/format
- tuts/python3/__builtins__/help
- tuts/python3/__builtins__/id
- tuts/python3/__builtins__/oct
- tuts/python3/__builtins__/ord
Related notes
- tuts/python3/__builtins__/__builtins__ Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/ascii Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/bin Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/chr Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/format Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/help Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/id Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__/oct Linked here; links to this page; shared tags: #builtins
- tuts/python3/__builtins__ links to this page; shared tags: #builtins
- tuts/python3/__builtins__/ord links to this page; shared tags: #builtins