Last Updated : 28 Mar, 2025
lower() method in Python converts all uppercase letters in a string to their lowercase. This method does not alter non-letter characters (e.g., numbers, punctuation). Let's look at an example of lower() method:
Python
s = "HELLO, WORLD!"
# Change all uppercase letters to lowercase
res = s.lower()
print(res)
Syntax of lower() method
string.lower()
Parameters: This method does not take any parameters.
Return Type : returns a new string with all uppercase characters converted to lowercase. The original string remains unchanged since strings in Python are immutable.
Examples of lower() Example 1. Case-Insensitive Comparisonlower() method is very useful in making case-insensitive comparisons between strings.
Python
s1 = "Python"
s2 = "python"
if s1.lower() == s2.lower():
print("The strings are equal.")
else:
print("The strings are not equal.")
The strings are equal.
Explanation: In this example, we convert both s1 and s2 to lowercase using lower() before comparing them. This approach ensures that the comparison is not affected by case differences.
Example 2. Normalizing User InputWhen dealing with user input, converting text to lowercase ensures uniformity, especially for tasks like comparing usernames or email addresses.
Python
e1 = "Geek@Example.com"
e2 = "Geek@example.com"
# Convert both to lowercase for comparison
if e1.lower() == e2.lower():
print("Emails match.")
else:
print("Emails do not match.")
Explanation: lower() method converts both email addresses to lowercase, allowing a case-insensitive comparison. This is useful when checking if two email addresses are the same, regardless of how they were entered.
Example 3. Keyword Matching in Searchlower() helps in making search operations case-insensitive by converting both the search query and text to lowercase.
Python
s = "GFG is the best place to learn Python."
k = "python"
# Convert both to lowercase for case-insensitive search
if k.lower() in s.lower():
print("Keyword found!")
else:
print("Keyword not found.")
Explanation: this code checks if the keyword "python" is present in the string s, regardless of case. By converting both s and k to lowercase using .lower(), the search becomes case-insensitive.
Example 4. Mixed StringsLet’s take an example to illustrate how lower() method works on a string that includes non-alphabetic characters.
Python
s = "Hello, World! 123 @Python"
# Change only uppercase letters to lowercase
res = s.lower()
print(res)
hello, world! 123 @python
Explanation: .lower() method converts all uppercase letters in the string s to lowercase, while special characters (!, @) and numbers (1,2,3) remain unchanged.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4