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
print("the lord of the rings".title())
Output
The Lord Of The Rings
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
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
str.capitalize()· Return a copy of the string with the first character in upper case and the rest in lower case.str.istitle()· Return True if the string is title-cased: each word starts with an upper-case letter followed by lower-case letters.str.upper()· Return a copy of the string with all cased characters converted to upper case.- Python Strings · tutorial