Python has two built-in methods that convert capitalized alphabetic letters into lower case which are following,
These methods access through dot notation which means in order to convert string into lowercase first a string has to store into 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
that converts the string into lowercase.
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.