When you’re working with a string in Python, you may want to convert the contents of that string to lowercase. In the real world, for example, we use the Python lower() method to change emails to lowercase to ensure that another user won’t send the same email using uppercase characters.
So, this article will make you understand more about the string
lower() method in Python with illustrations and examples.
What is Python lower?
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
String lower() Parameters
There are no parameters in the string
String lower() Return Value
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.
# 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 [email protected] D0g!" print(sample.lower()) # the string below contains lowercase characters only sample = "the quick brown fox jumps over the lazy dog!" print(sample.lower())
the quick brown fox jumps over the lazy dog! th3 qu!ck br0wn f0x jump$ 0v3r th3 [email protected] 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)
Search your favorite animal: eagle eagle is found -------------- Search your favorite animal: bear bear is not found. Please try again.
Frequently Ask Questions
What does lower() mean in Python?
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.
How do you write lower in Python?
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.
Python lowercase list
To convert a list of strings inside the list, we have to use the
programming_language = ["Python", "Ruby on Rails", "HTML5", "MySQL", "CSS3"] new_list =  for language in programming_language: new_list.append(language.lower()) print(new_list)
['python', 'ruby on rails', 'html5', 'mysql', 'css3']
What is the opposite of lower in Python?
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.
For more information about Python, you can check out our website to see a bunch of tutorials with examples.
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.