Bytearray Methods

bytearray.reverse()

Reverse the order of bytes in place without changing the length or identity of the buffer. Existing aliases and active memoryviews observe the new byte order. Returns None rather than a new buffer. Reversing encoded Unicode bytes can invalidate the encoding; reverse text after decoding if text order is the goal. Reversing a byte sequence twice restores its original values.

Formal Syntax & Structure

python syntaxpython
data.reverse()

Return Value

None

None; modifies the existing buffer.

Working Example

Example Snippetpython
data = bytearray(b"ABC")with memoryview(data) as view:    print(data.reverse())    print(bytes(view))print(data)
Python Reference