Skip to content

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.

Beginner 8 min read·Lesson 91 of 306 in Python Programming

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

Python
if answer.strip().lower() == "yes":
pass
key = email.strip().lower()
  • Lower both sides of a comparison.
  • Combine with strip() for user input.
  • Use casefold() for international text.

Code examples

Lower-casing

Python
print("Hello WORLD 2026".lower())
print("abc".islower(), "Abc".islower(), "123".islower())
Output
hello world 2026
True False False

Case-insensitive answers

Python
for answer in ["Yes", "YES", " yes ", "no"]:
print(repr(answer), answer.strip().lower() == "yes")
Output
'Yes' True
'YES' True
' yes ' True
'no' False

More examples

Duplicate sign-ups and casefold()

Python
emails = ["Asha@Mail.com", "ben@mail.com", "asha@mail.com ", "BEN@MAIL.COM"]
seen = set()
for e in emails:
key = e.strip().lower()
if key in seen:
print("Duplicate:", e.strip())
else:
seen.add(key)
print("Unique accounts:", len(seen))
print("Straße".lower() == "STRASSE".lower())
print("Straße".casefold() == "STRASSE".casefold())
Output
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:

TextOutput
Duplicate: asha@mail.com
Duplicate: BEN@MAIL.COM
Unique accounts: 2
False
True

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

if name.lower() == "Asha":

Prefer

if name.lower() == "asha":

Comparing a lower-case value with a capitalised literal can never be True.

Replacing the user’s display text

Avoid

name = name.lower() # then shown on screen

Prefer

name_key = name.lower() # keep name for display

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

  1. 1
    Check whether a word appears in a sentence regardless of case.
  2. 2
    Count 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?
Practise this topic