Browse by Topic

Popular

Latest

Latest Posts

A diagram showing a memoryview referencing the same underlying buffer as a bytearray, with a slice pointing into the buffer without copying.
Python

Python memoryview Usage: Avoiding Copies in Binary Data

Learn how Python's memoryview reads and modifies binary data without copying, including slicing, casting, writable views, and where the performance benefit is real.

memoryviewbuffer protocolbinary datapython performance
Illustration of a Python memoryview showing a zero-copy slice referencing the same underlying buffer as the original bytearray.
Python

Python memoryview: Zero-Copy Buffer Access

Learn how Python memoryview provides zero-copy access to an object's underlying buffer, enabling efficient slicing and manipulation of binary data without unnecessary copies.

memoryviewbuffer protocolzero-copybytes
Diagram showing a hexadecimal string being converted into a bytes object using Python's bytes.fromhex() method.
Python

Python bytes.fromhex(): Convert Hex Strings to Bytes

Use Python's bytes.fromhex() method to convert hexadecimal strings into bytes objects. Includes whitespace handling, ValueError cases, bytes vs bytearray choices, and practical examples.

byteshex parsingbinary datastring conversion
Diagram showing a byte sequence on the left converting to a hexadecimal string on the right, with arrows indicating the conversion process.
Python

Converting Between Bytes and Hex in Python

Learn to convert bytes to hex strings and back in Python with bytes.hex(), bytes.fromhex(), and binascii, including code examples and memory considerations.

byteshexbinasciiencoding
Diagram showing a bytes object sliced into segments with indices and step, illustrating Python bytes slicing.
Python

Python Bytes Slicing: Syntax and Behavior

python bytes slicing: Learn how to slice bytes objects in Python: syntax, step, negative indices, copy behavior, and practical binary data extraction.

bytesslicingbinary datamemoryview
Illustration of indexing into a Python bytes object showing integer values at positions.
Python

Python Bytes Indexing: How It Works and Where It Breaks

Indexing into a Python bytes object returns an integer, not a one-byte bytes object. Learn how bytes indexing and slicing work and avoid common binary data pitfalls.

bytesindexingslicingbytearray
Side-by-side comparison of Python bytes and bytearray showing immutable vs mutable binary sequences
Python

Python bytes vs bytearray: Choosing the Right Binary Type

Compare Python's bytes and bytearray types: mutability, memory behavior, performance, and when to use each for binary data handling.

Pythonbytesbytearraybinary data
Diagram showing a bytearray as a mutable sequence of bytes with modification arrows
Python

Python bytearray: Mutable Bytes for Binary Data

Learn how to create, modify, and convert Python bytearray objects for binary data handling, with practical examples for network packets, file editing, and common pitfalls.

bytearraybytesbinary datamutable sequence
A visual representation of Python bytes literal syntax showing the b prefix and binary data.
Python

Python Bytes Literal Explained with Examples

python bytes literal: Learn how to write and use Python bytes literals, including syntax, encoding, and common pitfalls when working with binary data.

Pythonbytesbinary dataencoding
Diagram showing a sequence of bytes as small squares with numeric values transforming into text characters via an encoding arrow.
Python

Working with Python Bytes: Creation, Encoding, and Binary I/O

Practical examples for creating, manipulating, encoding, and decoding Python bytes, including binary I/O and performance tips.

bytesbinary dataencodingPython 3