Python capitalize() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In Python, capitalize() returns a new string with the first character uppercased and the rest lowercased. The original string does not change.

It takes no arguments. Prefer title() when every word should start with a capital letter.

Syntax

Call capitalize on the string. Start with this line.

python
result = text.capitalize()
CallWhat it does
"python is fun".capitalize()Returns "Python is fun".
"123ABC".capitalize()Returns "123abc" (leading digits stay).

Strings are immutable. Always assign or print the return value.

Library declarations
python
str.capitalize() → str

Parameters

This method has no parameters.

Return Value

Return ValueDescription
strA new string with sentence-style casing.

Python Examples

Example 1 — Basic capitalize()

Turn a lowercase phrase into sentence case and prove the original stays put.

python
original = "python is fun"
result = original.capitalize()

print("Original:", original)
print("Capitalized:", result)

How It Works

  1. Store the text. original is all lowercase.
  2. Call capitalize. Returns a new string into result.
  3. First letter rises. p becomes P; the rest stay lowercase words.
  4. Original untouched. Immutability keeps original as "python is fun".

Example 2 — Strip, Then Capitalize

Clean messy input before casing—spaces first, then the first letter.

python
raw_name = "  mari  "
clean_name = raw_name.strip().capitalize()

print(clean_name)

How It Works

  1. Start messy. Extra spaces surround the name.
  2. strip() first. Removes leading/trailing whitespace → "mari".
  3. capitalize() next. First letter becomes M.
  4. Chain reads left to right. Each method returns a new string for the next call.

Example 3 — capitalize() vs title()

The classic beginner mix-up: one first letter vs every word.

python
name = "john doe"

print("capitalize():", name.capitalize())
print("title():     ", name.title())

How It Works

  1. Same input. Both methods start from "john doe".
  2. capitalize(). Only index 0 rises → "John doe".
  3. title(). Each word’s first letter rises → "John Doe".
  4. Pick by goal. Sentences → capitalize; names/headings → title.

Frequently Asked Questions

It returns a new string with the first character uppercased and the rest lowercased.
No. Python strings are immutable. It always returns a new string.
capitalize() affects only the first character of the whole string. title() capitalizes each word.
It returns an empty string. No error is raised.
Remaining letters are still lowercased. For example, "123ABC".capitalize() returns "123abc".

Next: casefold()

Learn case-insensitive matching with Unicode-aware folding.

casefold() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful