Title() Method Of Str Class

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:

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:

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

 

 


Copyright 2023 © pythontic.com