Python 3 – String lower() Method
In Python 3, the lower()
method is used to convert all uppercase letters in a string into lowercase letters. It returns a new string with all the lowercased characters.
Syntax
string.lower()
Parameters
This method takes no parameters.
Return Value
This method returns a new string with all the uppercase characters in the original string converted to lowercase.
Example
string = "HELLO, WORLD!"
print(string.lower())
Output:
hello, world!
In the above example, as we can see, the lower()
method has converted all the uppercase characters into lowercase characters.
We can use the lower()
method to convert a string into lowercase so that we can perform case-insensitive string comparisons. Let’s take an example.
string1 = "Hello, World!"
string2 = "hello, world!"
if string1.lower() == string2.lower():
print("The strings are equal.")
else:
print("The strings are not equal.")
Output:
The strings are equal.
As we can see in the above example, the lower()
method is used to convert both strings to lowercase. This makes the two strings equal, and the program prints that the strings are equal.
We can use the lower()
method to convert all uppercase letters in a string to lowercase. Let’s take an example.
string = "CONVERT TO LOWERCASE"
print(string.lower())
Output:
convert to lowercase
As we can see in the above example, the lower()
method has converted all uppercase characters in the string into lowercase characters.
Conclusion
The lower()
method is a useful method that can be used to convert all uppercase letters in a string into lowercase letters. It can be used to perform case-insensitive string comparisons and also to convert strings to lowercase.