Python Reference Library →

Python String title() Method – Convert to Title Case

Let’s look at string title() method – convert to title case

  1. Notice

    title() returns titlecased text using its definition of word boundaries. Apostrophes can create surprising boundaries.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
text = 'hello world'
result = text.title()
print(result)
Live state

Top-level scope

text→Object 1
result→Object 2
Object 1 · str'hello world'Object 2 · str'Hello World'
This step

title() returns titlecased text using its definition of word boundaries. Apostrophes can create surprising boundaries.

Picture string title() method – convert to title case

title() returns titlecased text using its definition of word boundaries. Apostrophes can create surprising boundaries.

Image brief

Alt text
A diagram for Python String title() Method – Convert to Title Case. Instructions: text = 'hello world' result = text.title() print(result). Displayed result: Hello World. The final example bindings are text --> object 1 (str); result --> object 2 (str). object 1: 'hello world'; object 2: 'Hello World'
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python String title() Method – Convert to Title Case". Teaching focus: title() returns titlecased text using its definition of word boundaries. Apostrophes can create surprising boundaries. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS text = 'hello world' result = text.title() print(result) | v DISPLAYED RESULT Hello World FINAL BINDINGS text --> object 1 (str) result --> object 2 (str) object 1: 'hello world' object 2: 'Hello World' Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python String title() Method – Convert to Title Case. Instructions: text = 'hello world' result = text.title() print(result). Displayed result: Hello World. The final example bindings are text --> object 1 (str); result --> object 2 (str). object 1: 'hello world'; object 2: 'Hello World'

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
text = 'hello world'
result = text.title()
print(result)
Live state

Top-level scope

text→Object 1
result→Object 2
Object 1 · str'hello world'Object 2 · str'Hello World'
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
Hello World

What do you expect this program to print?

What does this example display?

text = 'hello world'
result = text.title()
print(result)
What does this example display?
Choose one answer. You can try again.

Answer and explanation

Hello World

Follow the printed values in order. The output is: Hello World

Which explanation matches what you learned?

Which explanation matches what you learned?
Choose one answer. You can try again.

Answer and explanation

title() returns titlecased text using its definition of word boundaries. Apostrophes can create surprising boundaries.

title() returns titlecased text using its definition of word boundaries. Apostrophes can create surprising boundaries.

More examples and reference

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())

What to remember

Connect what you noticed in the example with the idea below.

Remember

title() returns titlecased text using its definition of word boundaries. Apostrophes can create surprising boundaries.

Watch out for this idea

title() understands all natural-language word boundaries perfectly.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →