Last Updated : 02 Jan, 2025
title() method in Python is a simple way to convert a string to a title case, where the first letter of each word is capitalized and all other letters are lowercase.
Let's understand with the help of an example:
Python
a = "hello geek"
# Converts string to title case
b = a.title()
print(b)
Syntax of String title()
Parametersstring.title()
When we ask users to input their names, we often receive names in lowercase or inconsistent formats. The title() method can help ensure that each part of the name starts with a capital letter.
Python
user_name = "geeky geek"
formatted_name = user_name.title()
print(formatted_name)
Cleaning Data for Database
When importing or processing data for a database, we may encounter strings that need to be formatted in title case. This ensures that data is consistent and easily readable when displayed in a user interface.
Python
city_name = "noida city"
formatted_city_name = city_name.title()
print(formatted_city_name)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4