How to convert all uppercase letters in string to lowercase in Python?



A string is a group of characters that may be used to represent a single word or an entire phrase. Strings are simple to use in Python since they do not require explicit declaration and may be defined with or without a specifier. Python has various built in functions and methods for manipulating and accessing strings. Because everything in Python is an object, a string is an object of the String class, which has several methods.

In this article, we are focusing on how to convert every uppercase letters into a string to lowercase letters.

Using the lower() method

One way to convert all the upper case letters into lower case using the inbuilt method lower() of the string library. This method converts all the characters present in a string to lowercase regardless of the character is uppercase or lowercase. It does not have any parameters to be tuned, it just converts the current string into lowercase.

Example 1

In the following example, we are taking a string as input and converting it into lower case using the lower() method.

str1 = "WELCOME TO TUTORIALSPOint" print("Converting the string to lowercase") print(str1.lower())

Output

The output of the above program is,

Converting the string to lowercase
welcome to tutorialspoint

Example 2

In the program given below, we are taking a string as input and then checking character by character whether it is a lower or upper case and then changing its case and adding it into a new string.

str1 ='WELCOME TO Tutorialspoint' lowerString ='' for a in str1: if (a.isupper()) == True: lowerString += (a.lower()) else: lowerString += a print("The lowercase of the given string is") print(lowerString)

Output

The output of the above program is,

The lowercase of the given string is
welcome to tutorialspoint

Example 3

In the example given below, we are taking the input of a combination of symbols, numbers, and characters and are converting it to lower case.

str1 = "HYDERABAD@1234" print("Converting the string to lowercase") print(str1.lower())

Output

The output of the above program is,

Converting the string to lowercase
hyderabad@1234

Example 4

In the example given below, we are taking the input of a combination of symbols, numbers, and characters and are converting it to lower case using the isupper() method.

str1 ='HYDERABAD@1234' lowerString ='' for a in str1: if (a.isupper()) == True: lowerString += (a.lower()) else: lowerString += a print("The lowercase of the given string is") print(lowerString)

Output

The output of the above program is,

The lowercase of the given string is
hyderabad@1234

Advertisements