title() method of str class

title() makes the first letter of every word in a string instance an upper cased letter and returns a copy of the string instance

Str Updated 15 Mar 2017 1 min read

Method Name

title

Method Signature

title()

Method Overview

  • title() makes every first letter of word in a string object an upper cased letter and returns a copy of it.

  • The algorithm does not handle apostrophes and acronyms in a sentence.

Example

python
sentenceCased       = "Gone with the wind"

titleCased          = sentenceCased.title()

print("Sentence cased string:%s"%(sentenceCased))

print("Title cased string:%s"%(titleCased))

#  Few exceptions how algorithm handles few cases

sentenceCased = "That doesn't matter"

titleCased    = sentenceCased.title()

print("Sentence cased string:%s"%(sentenceCased))

print("Title cased string:%s"%(titleCased))

sentenceCased = "XYZ is an acronym"

titleCased    = sentenceCased.title()

print("Sentence cased string:%s"%(sentenceCased))

print("Title cased string:%s"%(titleCased))

Output

Output
Sentence cased string:Gone with the wind

Title cased string:Gone With The Wind

Sentence cased string:That doesn't matter

Title cased string:That Doesn'T Matter

Sentence cased string:XYZ is an acronym

Title cased string:Xyz Is An Acronym