Last updated on March 9, 2023
Python has two built-in methods that convert capitalized alphabetic letters into lowercase which are the following,
These methods access through dot notation which means in order to convert the string into lowercase, first a string has to store into a variable.
1. casefold() Method
To use the casefold() method, let’s assign a string that contains uppercase letters to favoriteProgramming variable and convert it into lowercase.
favoriteProgramming = "I Like Python Programming Language." convertedString = favoriteProgramming.casefold()
In this example, the string is stored into a variable that is
favoriteProgramming. In the second line the casefold() method is attached with
favoriteProgramming variable that converts the string into lowercase. To see the result we can use the print() function.
print(convertedString) # OutPut: i like python programming language.
In the output the script returns a converted string that is lowercase.
2. lower() Method
The lower() method is similar to the
casefold() method and it works in the same way as
casefold(). Let’s look at the code below that is using the
lower() method to convert the string into lowercase.
bestLanguage = "Python Is BEST One." convertedString = bestLanguage.lower()
In this example, the
bestLanguage variable stored a string that contains uppercase letters. In the second line of above script we attached lower() method with
bestLanguage variable for converting the string into lowercase.
print(convertedString) # Output: python is best one.
As above, we got a lowercase string in the output which is converted by lower() method.