Open In App

Python String Title method

Last Updated : 02 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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)

Output
Hello Geek

Syntax of String title()

string.title()

Parameters

  • title() doesn't accept any parameter.

Return type

  • string, converted to title case.

Creating Proper Names from User Input

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) 

Output
Geeky Geek

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)  

Output
Noida City

Next Article

Similar Reads