Memoryview Methods

memoryview.hex()

Produce lowercase hexadecimal text from the logical bytes of a view, including strided data. Each byte contributes two digits. An optional single ASCII separator groups bytes; a positive group size counts from the right, a negative size from the left. Zero disables grouping on CPython. This is a textual snapshot, not a live view. It represents raw bytes rather than numeric element values.

Formal Syntax & Structure

python syntaxpython
view.hex()view.hex(sep, bytes_per_sep=1)

Parameters & Attributes

NameTypeDescription
sepstr | bytesOptional single ASCII separator.
bytes_per_sepintGrouping size; default 1.

Return Value

str

Hexadecimal text with optional grouping.

Working Example

Example Snippetpython
view = memoryview(b"ABCDEF")[::2]print(view.hex())print(view.hex(":", 2))print(view.hex(":", -2))
Python Reference