Module 7 · Strings — topic 10 of 22
lower()
lower() returns a lower-case copy of a string. Learn why it is the standard tool for case-insensitive comparisons, how casefold() differs, and how islower() works.
Learning objectives
- Convert text to lower case
- Compare text case-insensitively
- Know when casefold() is more correct than lower()
Definition
lower() returns a lower-case copy of a string. Learn why it is the standard tool for case-insensitive comparisons, how casefold() differs, and how islower() works.
Introduction
lower() returns a copy of a string with all cased letters converted to lower case. It is the everyday tool for making text comparisons ignore capitalisation.
Why it matters
Users type Yes, YES and yes and mean the same thing. Email addresses and usernames are usually treated as case-insensitive. Lower-casing both sides before comparing avoids treating identical answers as different.
Detailed explanation
Lower case is the usual choice for normalised keys because most text is mostly lower case already, so the stored keys stay readable when you print them while debugging.
Normalising case is part of a wider idea called canonicalisation: turning different ways of writing the same value into one standard form before comparing or storing it. For text, canonicalisation usually means strip() to remove outer spaces, lower() or casefold() for case, and sometimes collapsing repeated inner spaces.
lower() can’t undo every difference. “colour” and “color” are still different words, so for search you may need further processing such as synonyms or spelling correction.
lower() takes no arguments and returns a new string; digits and symbols are unchanged.
To compare case-insensitively, lower both sides: a.lower() == b.lower().
casefold() is a more aggressive version designed for comparisons across languages. "Straße".lower() is "straße" but "Straße".casefold() is "strasse", which matches "STRASSE".casefold(). For English text, lower() and casefold() behave the same.
islower() is True if there is at least one cased letter and all cased letters are lower case.
Store the original text for display and compare a lower-cased copy, so users still see their own capitalisation.
Normalising once, when data enters the program, is cleaner than calling lower() in every comparison.
Syntax
- Lower both sides of a comparison.
- Combine with strip() for user input.
- Use casefold() for international text.
Code examples
Lower-casing
hello world 2026 True False False
Case-insensitive answers
'Yes' True 'YES' True ' yes ' True 'no' False
More examples
Duplicate sign-ups and casefold()
Duplicate: asha@mail.com Duplicate: BEN@MAIL.COM Unique accounts: 2 False True
Step-by-step explanation
- Each email is stripped and lower-cased to form a comparison key.
- If the key was seen before, the sign-up is reported as a duplicate.
- Two of the four entries are duplicates, leaving two unique accounts.
- lower() doesn’t treat ß and SS as equal, but casefold() does.
Expected output
Running “Duplicate sign-ups and casefold()” prints exactly:
Practical applications
- Login systems compare email addresses case-insensitively.
- Search boxes lower-case queries and data before matching.
- Command-line tools accept options in any case by lower-casing them.
Best practices
- Normalise case when data enters the program.
- Compare lower-cased keys, display originals.
- Use casefold() for multilingual comparisons.
Common mistakes
Lowering only one side
Avoid
Prefer
Comparing a lower-case value with a capitalised literal can never be True.
Replacing the user’s display text
Avoid
Prefer
Keep the original for display; use a lower-cased key for comparisons.
Key takeaways
- lower() returns a lower-case copy.
- Lower both sides for case-insensitive comparison.
- casefold() handles special cases such as ß.
Try it yourself
- 1Check whether a word appears in a sentence regardless of case.
- 2Count how many times the word "the" appears in a paragraph, in any capitalisation.
Finished reading? Mark it complete to update your dashboard.
Suggested practice
1 question test this exact topic. Answers and explanations are revealed after you submit.
- BeginnerAfter name = "Hello" and name.lower(), what is name?