Convert a string to title case in Python
Hello friends, in this tutorial I will tell you how to convert a string variable’s case to title case in Python.
In short, it will convert the first letter of each word to upper case with the built-in method provided by Python.
Convert a string to title case in Python using .title()
title()
function converts any string to title case. Title case is one where the first character of every word is uppercase and the others are converted to lowercase. In the example, I have taken a string, sample_Str
which stores a string value of mixed case. After using the title() function, it returns a string in title case format.
Code :
sample_Str = 'thiS is codeSpeedy.' new_Str = sample_Str.title() print(new_Str)
Output :
This Is Codespeedy.
Thus you can now successfully convert a string to title case.
Leave a Reply