Memoryview Attributes

memoryview.nbytes

Report the byte count of a packed representation of the logical elements. It equals the product of dimensions multiplied by itemsize and the length of tobytes(). For a strided view this excludes skipped bytes; it does not report the span of addresses touched or the size of the original exporter. Unlike len(view), this also counts elements beyond the first dimension. Read-only attribute.

Formal Syntax & Structure

python syntaxpython
view.nbytes

Return Value

int

Logical byte count.

Working Example

Example Snippetpython
view = memoryview(b"ABCDEF").cast("B", [2, 3])print(len(view), view.nbytes)part = memoryview(b"ABCDEF")[::2]print(part.nbytes, len(part.tobytes()))
Python Reference