Python String lower() Method
The lower() method in Python is used to convert all the characters in a string to lowercase. It's useful when comparing strings or working with user input where case sensitivity doesn't matter.
Syntax
string.lower()
Parameters:
- None – This method does not take any arguments.
Returns:
- A new string where all uppercase characters are converted to lowercase.
Example 1: Basic Usage
text = "HELLO WORLD"
print(text.lower())
hello world
Example 2: Mixed Case String
greeting = "GoOd MoRnInG"
print(greeting.lower())
good morning
Why Use lower()?
- To make string comparison case-insensitive.
- To clean up user input before storing or validating.
- To normalize data for searching or sorting.
Example 3: Comparing Strings
a = "Python"
b = "PYTHON"
print(a.lower() == b.lower())
True
Even though the original strings differ in case, they are equal after using lower().
Does lower() Change the Original String?
No, strings in Python are immutable. The lower() method returns a new string — it doesn’t modify the original one.
Common Mistake
name = "ALICE"
name.lower()
print(name)
ALICE
Why? Because name.lower() returns a new string, but it wasn't assigned back to name.
Correct Way:
name = name.lower()
print(name)
Summary
lower()converts a string to lowercase.- Returns a new string — original is not changed.
- Helps with case-insensitive comparisons and text cleaning.
Practice Problem
Ask the user to input a sentence and print it in lowercase.
text = input("Enter a sentence: ")
print("In lowercase:", text.lower())
Comments
Loading comments...