Bytes Methods

bytes.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. The original bytes remain unchanged; do not depend on the result having a different identity. These operations are intended for ASCII-compatible data, not arbitrary binary formats.

Formal Syntax & Structure

python syntaxpython
data.swapcase()

Return Value

bytes

bytes containing the transformed byte values; receiver unchanged.

Working Example

Example Snippetpython
data = bytes(b'Api READY 7')result = data.swapcase()print(result)print(bytes(b'\xffAa').swapcase())print(data)
Python Reference