struct.unpack()
struct.unpack() is a Python function in the Struct Module category. Unpacks bytes into values according to a format string. The syntax is struct.unpack(format, buffer). Parameters: format, buffer. Returns: Tuple of values. A typical example: values = struct.unpack(">I", b"\x00\x00\x00*")
values[0] # 42. A close sibling is struct.pack(), which packs values into a bytes object according to a format string. A close sibling is struct.calcsize(), which returns the size of the struct (and bytes needed) for the given format. A close sibling is struct.pack_into(), which packs values into a buffer (bytearray) at the given offset. A close sibling is struct.unpack_from(), which unpacks bytes from a buffer starting at offset. More about this category: Binary data packing — pack, unpack, calcsize, pack_into. For a broader walkthrough, read the Struct Module guide. Related Struct Module entries: struct.pack(), struct.calcsize(), struct.pack_into(), struct.unpack_from(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.