Memoryview Attributes

memoryview.itemsize

Report how many bytes represent one logical element, not the total byte length. Native numeric sizes can vary across platforms; compare with the actual exporter or struct.calcsize() for supported formats. A slice with a step changes spacing between elements, not their element size. This read-only field is distinct from strides and nbytes.

Formal Syntax & Structure

python syntaxpython
view.itemsize

Return Value

int

Bytes per element.

Working Example

Example Snippetpython
import arrayvalues = array.array("B", [1, 2, 3, 4])view = memoryview(values)print(view.itemsize, view.nbytes)print(view[::2].itemsize, view[::2].nbytes)
Python Reference