Python bytes.lower() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
bytes method

Definition

bytes.lower() returns a new bytes object where each byte from A (65) to Z (90) is replaced by its lowercase partner; every other byte is copied as it is.

It is the usual first step for case-insensitive comparisons of ASCII protocol data: commands typed into a socket, header names, or hex digits. Bytes from 128 to 255 are never changed, even if they encode uppercase letters in some text encoding.

bytes.lower() is a method of the built-in bytes type: call it on a bytes object with dot notation, such as data.lower(...). No import is needed, and bytearray objects have the same method.

Syntax

No arguments; assign or compare the returned copy.

python
result = data.lower()
CallWhat it does
b"PING".lower()Returns b'ping'.
b"MAC=AA:BB".lower()Returns b'mac=aa:bb'.
b"\xc4BC".lower()Returns b'\xc4bc': the non-ASCII byte is unchanged.

The result always has the same length as the input.

Method signatures
python
bytes.lower()
# returns a new bytes object (bytearray.lower() returns a bytearray)

Parameters

lower() takes no parameters.

Return Value

Return ValueDescription
bytesA copy with ASCII uppercase letters converted to lowercase.

Python Examples

Example 1 — Match Commands in Any Case

A server receives commands typed by people in mixed case, some with a trailing CRLF. Strip and lower each one before comparing.

python
commands = [b"PING", b"Quit", b"help", b"STATUS\r\n"]

for raw in commands:
    cmd = raw.strip().lower()
    print(cmd, cmd == b"quit")

How It Works

  1. Clean then compare. strip() removes the CRLF and lower() removes case differences.
  2. Chained calls. Each method returns new bytes, so the calls can be chained in one expression.
  3. One match. Only b"Quit" becomes b'quit' and equals the expected command.

Example 2 — Normalize Hex Digests and MAC Text

Checksums and MAC addresses are often written in uppercase hex. Lowercasing makes them comparable; digits and punctuation pass through.

python
digest = b"9F86D081884C7D65"

print(digest.lower())
print(b"MAC=AA:BB:0C".lower())
print(b"ABC\xc4\xd6".lower())

How It Works

  1. Letters only. In the digest only F, D, and C change; the digits stay as they are.
  2. Punctuation kept. = and : are not letters, so the MAC text keeps its shape.
  3. High bytes ignored. \xc4 and \xd6 are uppercase letters in Latin-1, but lower() only knows ASCII.

Example 3 — lower() on bytes and on bytearray

Check that the source stays unchanged and that the return type follows the type you call the method on.

python
raw = b"Content-Length"
buf = bytearray(b"Content-Length")

print(raw.lower(), raw)
print(buf.lower())
print(type(buf.lower()).__name__)

How It Works

  1. Source untouched. raw still prints with capitals after the call.
  2. Same method on bytearray. The mutable type has lower() too, but it still returns a new object.
  3. Type preserved. The result of buf.lower() is a bytearray, not bytes.

Frequently Asked Questions

No. Only A-Z are changed. Encoded non-ASCII letters are left as they are; decode and use str.lower() for Unicode text.
Compare a.lower() == b.lower(). This works for ASCII letters.
No. casefold() exists only on str.
No. It returns a new object; even bytearray.lower() returns a new bytearray.
No. Each byte maps to exactly one byte, so the length stays the same.

Next: bytes.lstrip()

Return a copy with leading bytes from a set removed (whitespace by default).

lstrip() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful