Python changes the case of a string with built-in methods: upper() makes every letter uppercase, lower() makes every letter lowercase, title() capitalises each word, capitalize() capitalises only the first character, and swapcase() flips each letter. These python upper lower title case methods all return a new string, because strings are immutable and the original is never changed.
For comparing text without regard to case, use casefold() instead of lower(). The examples below run on Python 3.13 and 3.14.
upper() and lower() are the two methods you use most often:
The last line shows that text itself did not change. If you want to keep the result, assign it to a name:
Characters that have no case, such as digits, spaces and punctuation, are left alone. Non-English letters work too, because the methods follow Unicode rules:
Notice that the German letter ß becomes two letters, SS, so the uppercase string can be longer than the original.
capitalize() makes the first character uppercase and the rest lowercase. title() does that for every word:
title() treats any run of letters as a word, so apostrophes cause surprising output:
If you need correct title case for names or headlines, use string.capwords(), which splits on whitespace:
Even capwords() does not know about small words such as "of" or "the" and also collapses repeated spaces, so real headline rules need your own code.
swapcase() turns uppercase letters into lowercase and the reverse:
It is rarely needed. Be aware that s.swapcase().swapcase() is not always equal to s for special Unicode characters, because some characters change length when their case changes.
Comparing two strings by lowercasing both usually works for English, but casefold() is designed for caseless matching and handles more languages:
Use casefold() for search, deduplication and comparing user input such as email domains or tags. Use lower() when you want text to display in lowercase. For strict checks you can also normalise with unicodedata.normalize("NFC", s) before comparing.
The matching test methods return True or False:
| Method | Returns True when |
|---|---|
s.isupper() | there is at least one cased letter and all are uppercase |
s.islower() | there is at least one cased letter and all are lowercase |
s.istitle() | every word starts uppercase followed by lowercase |
"123".isupper() is False because the string has no cased letters.
Normalise user input before storing or comparing it:
Turn a name into a constant-style identifier:
Methods can be chained because each one returns a string.
No. Strings are immutable, so upper() returns a new string and leaves the original as it was. Assign the result to keep it.
casefold() is a more aggressive form of lowercasing meant for comparisons, and it maps characters such as ß to ss. Use it when you compare strings without regard to case.
Use capitalize(), but note that it lowercases the rest of the string. To keep the rest as it is, use s[:1].upper() + s[1:].
It splits words at every non-letter character. Use string.capwords() or write a small function for names and headlines.
Use upper(), lower(), capitalize(), title() and swapcase() to change case, and remember they all return new strings. Choose casefold() for caseless comparison, watch for the apostrophe behaviour of title(), and use isupper(), islower() and istitle() to test the case of existing text.