Python bytes.title() Method

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

Definition

bytes.title() returns a new bytes object in title case: the first ASCII letter of each word is uppercase and the following letters are lowercase.

A "word" is simply a run of ASCII letters. Any other byte, such as a space, hyphen, digit, apostrophe, or a non-ASCII byte, ends the word, so the next letter starts a new one. That makes title() great for HTTP-style header names and surprising for text like it's.

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

Syntax

No arguments; the title-cased copy is returned.

python
result = data.title()
CallWhat it does
b"content-type".title()Returns b'Content-Type'.
b"HELLO wORLD".title()Returns b'Hello World'.
b"3rd".title()Returns b'3Rd': the digit breaks the word.

The rule is purely mechanical; it knows nothing about real words or names.

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

Parameters

title() takes no parameters.

Return Value

Return ValueDescription
bytesA copy where each run of ASCII letters starts uppercase and continues lowercase.

Python Examples

Example 1 — Format HTTP Header Names

Header names are case-insensitive, but they are conventionally written with a capital after each hyphen. title() does exactly that.

python
for name in [b"content-type", b"x-request-id", b"user agent"]:
    print(name.title())

How It Works

  1. Hyphen breaks words. After each hyphen the next letter is uppercased.
  2. Single letters too. The one-letter word x becomes X.
  3. Spaces work the same. Any non-letter byte, including a space, starts a new word.

Example 2 — Apostrophe and Digit Pitfalls

Title-case a phrase containing an apostrophe and an ordinal number, then check the result with istitle().

python
phrase = b"it's 3rd time"

print(phrase.title())
print(phrase.title().istitle())
print(b"HELLO wORLD".title())

How It Works

  1. Double-quoted repr. The result contains a single quote and no double quote, so Python prints it inside b"...".
  2. Unexpected capitals. The apostrophe and the digit 3 end a word, so S and R are uppercased.
  3. Consistent check. istitle() uses the same word rule, so it accepts the result.
  4. Lowers the rest. Shouted or inverted words are fixed: only the first letter of each stays capital.

Example 3 — Non-ASCII Bytes Split Words

Title-case UTF-8 bytes and compare with the str method, which understands accented letters.

python
print(b"caf\xc3\xa9 bar".title())
data = "\u00e9t\u00e9".encode("utf-8")
print(data.title())
print(ascii("\u00e9t\u00e9".title()))

How It Works

  1. Normal case. In caf\xc3\xa9 bar the words start with ASCII letters, so C and B are raised.
  2. Mid-word capital. The encoded word starts with two non-ASCII bytes; the t that follows looks like the start of a word and becomes T.
  3. str gets it right. Decoded text title-cases the first accented letter instead, shown by ascii() as \xc9.

Frequently Asked Questions

Any run of ASCII letters. Spaces, digits, punctuation, and non-ASCII bytes all end a word.
The apostrophe is not a letter, so the s after it starts a new word and is uppercased.
title() uppercases the first letter of every word; capitalize() uppercases only the first byte of the whole object.
Only for ASCII letters. Decode to str and use str.title() for accented letters.
Yes, a new bytes object; on a bytearray it returns a bytearray.

Next: bytes.translate()

Map every byte through a 256-byte table and optionally delete some bytes.

translate() →

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