Bytearray Methods
bytearray.swapcase()
Switch ASCII uppercase letters to lowercase and lowercase letters to uppercase. All other byte values are unchanged. Applying this binary operation twice restores the original byte values; Unicode str.swapcase() does not offer the same general guarantee. Returns a new mutable buffer even when no changes are needed; the original is untouched. These operations are intended for ASCII-compatible data, not arbitrary binary formats.
Formal Syntax & Structure
python syntaxpython
data.swapcase()Return Value
bytearray
bytearray containing the transformed byte values; receiver unchanged.
Working Example
Example Snippetpython
data = bytearray(b'Api READY 7')result = data.swapcase()print(result)print(bytearray(b'\xffAa').swapcase())print(data)print(result is data)