title()

title(): Change First letter of each word to upper case
my_str='welcome to plus2net python section'
output=my_str.title()
print(output)

my_str='welcome #id 15of  plus2net'
output=my_str.title()
print(output)
Output
Welcome To Plus2Net Python Section
Welcome #Id 15Of  Plus2Net
This also changes the first char after any number of special chars ( check plus2Net )

Handling Mixed Cases

What happens when the string is already in mixed case? title() still ensures that only the first letter of each word is capitalized:

my_str = 'pYTHON tUTORIAL'
output = my_str.title()
print(output)  # Output: 'Python Tutorial'

Use Case: Formatting Names

This is useful when you want to format names or titles in proper case for user-facing applications:

full_name = 'john doe'
formatted_name = full_name.title()
print(formatted_name)  # Output: 'John Doe'

Handling Special Characters

When a word contains special characters, only the letter after the special character will be capitalized:


my_str = "welcome to plus2net's python"
print(my_str.title())  # Output: "Welcome To Plus2Net'S Python"

Use Case: Formatting Book Titles

It's useful for standardizing book or article titles in publishing applications:

book_title = "harry potter and the goblet of fire"
print(book_title.title())  # Output: "Harry Potter And The Goblet Of Fire"

Difference with capitalize()

While title() capitalizes each word, capitalize() affects only the first word:

text = "hello world"
print(text.capitalize())  # Output: "Hello world"

All String methods


Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer