BBampaa

Lessons › Python

Python lesson

.upper(), .lower() and .title()

LAGOS, lagos, then Ada Okafor. city and name don't change: the methods hand back a copy.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Text methods go after the text, joined by a dot, and give back a changed copy. .upper() makes capitals, .lower() makes small letters, .title() puts a capital at the start of each word:

city = "Lagos"
print(city.upper())
print(city.lower())
name = "ada okafor"
print(name.title())

Output:

LAGOS
lagos
Ada Okafor

Key points

.upper()A copy in capitals: LAGOS.
.lower()A copy in small letters: lagos.
.title()A copy with a capital at the start of each word: ada okafor becomes Ada Okafor. Handy for names.

Put together: print(name.title()). To keep the change, store it: name = name.title().

Practice

Try each one in your head first, then open the answer.

1. Build a line that shows city in capitals.
print(city.upper())
2. Build a line that stores product in small letters in a variable called p.
p = product.lower()
3. store holds abuja. Print it in capital letters.
store = "abuja"
print(store.upper())
4. name holds TUNDE. Print it in small letters.
name = "TUNDE"
print(name.lower())
5. customer holds ada okafor. Print it with a capital at the start of each word.
customer = "ada okafor"
print(customer.title())

Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.

Try this lesson free →
About 5–10 minutes · no sign-up needed