Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 02

Case Conversion Methods

Learn capitalize(), title(), upper(), lower(), and swapcase() with visual syntax, memory tricks, and transformation flows.

Beginner20 min

Learning roadmap

Cap → Title → UP → low → Swap learning path

You'll learn these five methods in the same order they're commonly used.

Syntax pattern (applies to every method)

text.upper() syntax breakdown
python
s = "python"

s.upper()
s.lower()
s.title()

Remember: object.method() → returns a new string.

1. capitalize()

Capitalizes only the first character of the entire sentence.

capitalize() before and after
python
s = "python is an oop lang"

print(s.capitalize())
# Python is an oop lang

Store the result:

python
s = s.capitalize()

Memory: One sentence → one capital.

2. title()

Capitalizes the first letter of every word.

title() before and after
python
s = "python is an oop lang"

print(s.title())
# Python Is An Oop Lang

Memory: Every word gets a title.

capitalize() vs title()

This is the most common interview question.

Method Result
capitalize() Python is an oop lang
title() Python Is An Oop Lang
capitalize vs title visual difference

3. upper()

Converts every letter to uppercase.

python to PYTHON transformation
python
s = "python"

print(s.upper())
# PYTHON

Digits and symbols stay unchanged:

python
print("abc123".upper())
# ABC123

4. lower()

Converts every letter to lowercase.

Data Science to data science transformation
python
s = "Data Science"

print(s.lower())
# data science

Real-world example:

python
email = "USER@GMAIL.COM"
email = email.lower()

5. swapcase()

Swaps uppercase ↔ lowercase.

PyThOn to pYtHoN swapcase transformation
python
s = "PyThOn"

print(s.swapcase())
# pYtHoN

Numbers remain unchanged:

python
print("12345".swapcase())
# 12345

Immutability reminder

Methods create a new string. The original stays unchanged until you reassign.

upper() returns new string; original unchanged

Without reassignment:

python
s = "python"

s.upper()

print(s)
# python

With reassignment:

python
s = s.upper()

print(s)
# PYTHON

Playground example

python
s = "python is an oop lang"

print("capitalize:", s.capitalize())
print("title:", s.title())
print("upper:", s.upper())
print("lower:", s.lower())
print("swapcase:", "PyThOn".swapcase())

Expected output:

text
capitalize: Python is an oop lang
title: Python Is An Oop Lang
upper: PYTHON IS AN OOP LANG
lower: python is an oop lang
swapcase: pYtHoN

Use the lesson playground at the bottom of the page to run this code live.

Method summary

Method Effect Memory
capitalize() First character uppercase One sentence
title() Every word uppercase Book title
upper() All letters uppercase Everything UP
lower() All letters lowercase Everything down
swapcase() Flip letter casing Reverse

Quick knowledge check

  1. Which method title-cases every word?
    Answer: title()

  2. After s.upper(), is s changed?
    Answer: No. Only if you assign: s = s.upper()

  3. What happens to digits in swapcase()?
    Answer: They remain unchanged.

30-second visual revision

Case methods hub diagram

Interview shortcut: One → capitalize() · Every → title() · All BIG → upper() · All small → lower() · Flip → swapcase()

Next: String Validation Methods.

Loading playground…