Python Program: Convert Lowercase to Uppercase
To convert lowercase to uppercase in Python, call .upper() on the string. That is the whole answer: "hello".upper() returns "HELLO". Strings are immutable in Python, so the method returns a new string rather than changing the original.
This page gives the complete program with input, the five other case methods and what each one really does, the Unicode cases where .upper() changes the length of the string, and why the ASCII arithmetic trick found in older tutorials is a bad idea.
Converting text rather than writing code? The free case converter handles UPPERCASE, lowercase, Sentence case, Title Case, camelCase, snake_case and six more in one click. No sign-up.
The one-line answer
text = "hello world"
print(text.upper())
# HELLO WORLD
.upper() returns a new string. The variable text still holds "hello world" afterwards. To keep the result, assign it:
text = text.upper()
A complete program
def main():
text = input("Enter some text: ")
print("Uppercase:", text.upper())
print("Lowercase:", text.lower())
print("Title Case:", text.title())
if __name__ == "__main__":
main()
Run it and type hello world, and it prints HELLO WORLD, hello world and Hello World. That is a genuine program rather than a snippet, which is what the phrase Python program to convert lowercase to uppercase usually means.
The six case methods
| Method | Input | Output | Use for |
|---|---|---|---|
.upper() | hello World | HELLO WORLD | Uppercase everything |
.lower() | Hello WORLD | hello world | Lowercase everything |
.capitalize() | hello WORLD | Hello world | First letter up, rest down |
.title() | hello world | Hello World | First letter of each word |
.swapcase() | Hello World | hELLO wORLD | Invert every letter |
.casefold() | Straße | strasse | Comparison, not display |
swapcase() is not an uppercase method. It inverts the case of every character, so it only produces uppercase when the input was entirely lowercase to start with. Give it "Hello" and you get "hELLO", not "HELLO". Several tutorials list it as a way to uppercase a string. It is not.
title() and its known flaw
.title() capitalizes the first letter after every non-letter character, which breaks on apostrophes:
print("it's a test".title())
# It'S A Test
The standard fix uses the string.capwords helper, which splits on whitespace instead:
import string
print(string.capwords("it's a test"))
# It's A Test
Note that neither produces true Title Case. Both capitalize of, the and to, which the style guides leave lowercase — the list of words that stay small is in words that are not capitalized in titles.
Where Unicode makes upper() interesting
| Input | .upper() gives | Note |
|---|---|---|
| café | CAFÉ | Accents handled correctly |
| Straße | STRASSE | One character becomes two |
| file | FILE | The fi ligature expands |
| مرحبا | مرحبا | Arabic has no case |
| Dž | DŽ | Titlecase characters exist too |
The German sharp s is the classic example: len("Straße") is 6 but len("Straße".upper()) is 7. Any code that assumes case conversion preserves length is wrong. So is any code that assumes s.upper().lower() == s.lower().
There is also a locale trap. In Turkish, the uppercase of i is İ rather than I. Python's .upper() does not apply locale rules, so text destined for a Turkish audience needs explicit handling.
Comparing strings: use casefold(), not lower()
a = "Straße"
b = "STRASSE"
print(a.lower() == b.lower()) # False
print(a.casefold() == b.casefold()) # True
.casefold() is an aggressive lowercase designed for caseless matching. Use it whenever you compare user input; use .lower() only when you intend to display the result.
Why not to use the ASCII trick
Older tutorials show manual conversion with character arithmetic:
text = "hello"
result = "".join(
chr(ord(c) - 32) if "a" <= c <= "z" else c
for c in text
)
print(result)
# HELLO
It works on plain English and fails on everything else. café comes back as cafÉ only if the guard is right, and silently unchanged if it is not; Greek, Cyrillic and accented Latin are all skipped. It is also slower than the built-in method, which is implemented in C. Use it to understand how ASCII is laid out, never in real code.
Converting a list, a file, or a DataFrame
| Target | Code |
|---|---|
| A list of strings | [s.upper() for s in items] |
| Dictionary keys | {k.upper(): v for k, v in d.items()} |
| Every line of a file | [line.upper() for line in open("in.txt")] |
| A pandas column | df["name"] = df["name"].str.upper() |
| Only the first letter | text[:1].upper() + text[1:] |
The last row is worth noting: it uppercases the first character without touching the rest, which .capitalize() would lowercase.
The same job in other places
JavaScript uses toUpperCase() and toLowerCase(). Java uses toUpperCase() with an optional Locale — the manual character-array approach and its limits are covered in converting lowercase to uppercase in Java. Excel uses =UPPER(A1), described in changing case in Excel. And for text you are not processing programmatically, an online case converter is faster than writing anything.
Twelve case styles, no code. The upper lower case converter also produces camelCase, PascalCase, snake_case, kebab-case and CONSTANT_CASE — handy for renaming variables. Free, no sign-up.
Frequently asked questions
How do I convert lowercase to uppercase in Python?
Call .upper() on the string: text.upper(). It returns a new string, so assign the result if you want to keep it.
Does upper() change the original string?
No. Python strings are immutable. .upper() returns a new string and leaves the original untouched.
What is the difference between upper() and swapcase()?
.upper() makes every letter uppercase. .swapcase() inverts each letter, so Hello becomes hELLO. Only .upper() reliably produces uppercase.
What is the difference between capitalize() and title()?
.capitalize() uppercases the first character and lowercases everything else. .title() uppercases the first letter of every word.
Why does title() produce It'S?
Because it capitalizes after every non-letter character, including the apostrophe. Use string.capwords() instead, which splits on whitespace.
Should I use lower() or casefold() to compare strings?
Use .casefold(). It handles cases such as the German sharp s that .lower() does not, which matters for any comparison of user input.
Does upper() work on non-English text?
Yes, on any script that has case, including Greek and Cyrillic. Scripts with no case, such as Arabic and Chinese, are returned unchanged.
How do I uppercase a whole column in pandas?
Use the string accessor: df["name"] = df["name"].str.upper().
The short version
.upper() for uppercase, .lower() for lowercase, .capitalize() for the first letter only, .title() for every word, .casefold() for comparisons. Ignore .swapcase() unless you actually want the case inverted, and never write the ASCII arithmetic version in production code — it breaks on the first accented character it meets.