Python 3 reference · String Methods

Python String title() Method

Return a title-cased copy: the first letter of each word upper case and the rest lower case.

Python 3 Since 3.0

Syntax

str.title()

Return value

A new string.

Examples

Basic useTry it yourself
print("the lord of the rings".title())

Output

The Lord Of The Rings
Apostrophes, and string.capwords()Try it yourself
print("they're bill's friends".title())
import string
print(string.capwords("they're bill's friends"))

Output

They'Re Bill'S Friends
They're Bill's Friends

title() treats apostrophes as word boundaries (They'Re). string.capwords() splits on spaces only.

Version history

VersionChange
Python 3.0Added