- 1Python String capitalize() – Capitalize First Letter of a String
- 2Python String casefold() – Case-Insensitive String Comparison
- 3Python String center() Method – Center Align a String with Padding
- 4Python String count() Method – Count Substring Occurrences
- 5Python string.encode() – Convert String to Bytes
- 6Python String endswith() – Check if a String Ends with Substring
- 7Python String expandtabs() – Replace Tabs with Spaces
- 8Python String find() – How to Locate Substrings Easily
- 9Python String index() Method – Find Position of a Substring
- 10Python String isalnum() Method – Check Alphanumeric Strings
- 11Python String isalpha() Method – Check for Alphabetic Characters
- 12Python String isascii() Method – Check for ASCII Characters
- 13Python String isdecimal() Method – Check if All Characters Are Decimals
- 14Python String isdigit() Method – Check If a String Has Only Digits
- 15Python String isidentifier() – Check for Valid Identifiers
- 16Python String islower() Method – Check for Lowercase Strings
- 17Python String isnumeric() Method – Check for Numeric Characters
- 18Python String isprintable() Method – Check Printable Characters
- 19Python String isspace() Method – Check for Whitespace Only
- 20Python String istitle() Method – Check for Title Case
- 21Python String isupper() Method – Check for Uppercase Letters
- 22Python String join() Method – Combine Strings Easily
- 23Python String ljust() Method – Left Justify a String with Spaces or Characters
- 24Python String lower() Method – Convert to Lowercase
- 25Python String lstrip() Method – Remove Leading Characters
- 26Python String maketrans() Method – Create Translation Tables
- 27Python String partition() Method – Split into Three Parts
- 28Python String replace() Method – Replace Substrings Easily
- 29Python String rfind() Method – Find Last Occurrence of Substring
- 30Python String rindex() Method – Find Last Occurrence of a Substring
- 31Python String rjust() Method – Right Justify a String
- 32Python String rpartition() Method – Split String from the Right
- 33Python String rsplit() Method – Split from the Right
- 34Python String rstrip() Method – Remove Trailing Characters
- 35Python String split() Method – Split Strings Easily
- 36Python String splitlines() Method – Split String by Line Breaks
- 37Python String startswith() Method – Check If a String Starts With
- 38Python String strip() Method – Remove Spaces from Ends
- 39Python String swapcase() Method – Convert Uppercase to Lowercase and Vice Versa
- 40Python String title() Method – Convert to Title Case
- 41Python String translate() Method – Replace Characters Using Mapping
- 42Python String upper() Method – Convert to Uppercase
- 43Python String zfill() Method – Pad String with Zeros
Python String title() Method – Convert to Title Case
Next Topic ⮕Python String translate() Method – Replace Characters Using Mapping
Python String title()
Method
The title() method in Python returns a copy of the string where each word starts with an uppercase letter and the remaining letters are lowercase. It’s useful for formatting titles, names, or headings.
Syntax
string.title()
Parameters:
None – this method does not take any arguments.
Returns:
A new string with the first letter of each word in uppercase and all other characters in lowercase.
Example: Basic Usage
text = "python is fun"
title_text = text.title()
print(title_text)
Python Is Fun
Example: Mixed Case Input
text = "wElcOme to PYTHON world!"
print(text.title())
Welcome To Python World!
Use Case: Formatting User Input
If you're building a form or app where users input names, you can use title()
to standardize formatting:
name = input("Enter your full name: ")
print("Formatted Name:", name.title())
Limitations
title()
capitalizes letters after any non-letter character, including numbers and punctuation.- It may not correctly handle acronyms or special cases (like “McDonald”).
Example: Words with Apostrophes or Special Characters
text = "they're learning python's power!"
print(text.title())
They'Re Learning Python'S Power!
This behavior might not be desirable in every case, so use title()
carefully.
When to Use title()
- To format headings or titles
- To display names in proper case
- To clean up text input from users
Common Mistake
Thinking title()
changes the original string. It does not. It returns a new string:
text = "hello world"
text.title() # This won't change text
print(text) # Output: hello world
Interview Tip
Know the difference between title()
and capitalize()
. title()
capitalizes the first letter of each word, while capitalize()
only affects the first letter of the entire string.
Summary
title()
returns a new string in title case- Does not modify the original string
- Useful for formatting names and titles
- Be cautious with punctuation and contractions
Practice Problem
Ask the user for a book title and print it in proper title case:
book = input("Enter book title: ")
print("Formatted:", book.title())