What is Python lower?
The lower() method in Python converts all the uppercase characters in a string to lowercase characters and returns a copy of it.
If the given string doesn’t contain any uppercase characters, it will return the original string.
This method doesn’t affect the symbols and numbers in the given string.
The definition above is based on the Official Documentation of Python about Built-in Types.
String lower() Syntax
This is the syntax of the string lower() method:
string.lower()
String lower() Parameters
There are no parameters in the string lower() method.
String lower() Return Value
The string lower() method returns a copy of a string that contains converted characters to lowercase from the given string.
If the given string does not contain an uppercase, number, or symbol, it will return the original string.
Convert a string to lowercase example program
We will look at several examples of how the Python String
method converts a string.lower()
# below is the sample string
sample = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG!"
print(sample.lower())
# below is the sample string with symbols and numbers
sample = "Th3 Qu!ck Br0wn F0X jUmP$ 0v3R th3 l@Zy D0g!"
print(sample.lower())
# the string below contains lowercase characters only
sample = "the quick brown fox jumps over the lazy dog!"
print(sample.lower())
Output:
the quick brown fox jumps over the lazy dog!
th3 qu!ck br0wn f0x jump$ 0v3r th3 l@zy d0g!
the quick brown fox jumps over the lazy dog!
How lower() is used in a program
Below, we will look at an example of how to use the lower()
method in an actual program.
animals = ['alligator', 'boar', 'cat', 'dog', 'eagle', 'fox', 'goat', 'hamster', 'iguana', 'jellyfish']
search = input("Search your favorite animal: ")
def findElement(listname, searchname):
for animal_name in listname:
if animal_name == searchname:
return True
return False
if findElement(animals, search.lower()):
print("%s is found" %search)
else:
print("%s is not found. Please try again." %search)
Output:
Search your favorite animal: eagle
eagle is found
--------------
Search your favorite animal: bear
bear is not found. Please try again.
Frequently Ask Questions
The string method lower() returns a new string that is all lowercase. If there are capital letters in the original string, it is going to change into a lowercase in the new string. Any lowercase letters, symbols, or numbers are not affected.
To write in lowercase in Python, you can use the str.lower() function. Simply add .lower() after the string variable to apply the lower method, and it will convert all the characters inside the string to lowercase characters.
The opposite of the lower() method is the upper() method. It is a built-in method used to convert strings as well. The string upper method returns a converted string from lowercase to uppercase characters.
Python lowercase list
To convert a list of strings inside the list, we have to use the for
loop.
Example:
programming_language = ["Python", "Ruby on Rails", "HTML5", "MySQL", "CSS3"]
new_list = []
for language in programming_language:
new_list.append(language.lower())
print(new_list)
Output:
['python', 'ruby on rails', 'html5', 'mysql', 'css3']
For more information about Python, you can check out our website to see a bunch of tutorials with examples.
Summary
In summary, the lower() method in Python is used to convert all the uppercase characters in a given string into lowercase characters.
But there are exceptions: the symbols and numbers cannot be converted to lowercase.
So now you know how to work with lowercase strings like an expert.