Open In App

Python String lower() Method

Improve
Improve
Like Article
Like
Save
Share
Report

Python string lower() method converts all letters of a string to lowercase. If no uppercase characters exist, it returns the original string.

Example:

Python3




string = "ConvErT ALL tO LoWErCASe"
print(string.lower())


Output

convert all to lowercase

Syntax of String lower()

string_name.lower()

Parameters

The lower() method doesn’t take any parameters. 

Returns

Returns a lowercase string of the given string

What is the Python String lower() Method?

The `lower()` method is a string method in Python. When applied to a string, it converts all the characters in the string to lowercase.

This is useful for standardizing and comparing strings without considering case differences. For example, if the original string is “Hello World,” applying `lower()` would result in “hello world.” It is a commonly used method for case-insensitive string operations.

How to use the Python string lower() Method?

To convert all characters of a string to lowercase just call the lower() function with the string. lower() function is an in-built string method and can be used with variables as well as strings. Let’s understand it better with an example:

Python3




string="HelloWorld"
print(string.lower())
print("HelloWorld".lower())


Output

helloworld
helloworld

How to Convert a String to Lowercase in Python

There are various ways to Lowercase a string in Python but here we are using some generally used methods to convert a string to lowercase:

  • Using lower() Function
  • Using map() with Lambda Function in lower() Method
  • Using List Join with lower() Method
  • Using map and str.lower with lower() Method
  • Using Swapcase() Function 
  • Using casefold() Function

Convert string to lower case using lower() method

Let’s see two different cases of using the lower() method.

  • Strings with Alphabetic Characters
  • Strings with Alphanumeric Characters

String With Alphabetic Characters 

In this example, code initializes a string variable ‘text’ with the value ‘GeEks FOR geeKS’, then prints the original string. It subsequently converts the string to lowercase using the `lower()` function and prints the result, demonstrating the case transformation.

Python3




text = 'GeEks FOR geeKS'
 
print("Original String:")
print(text)
 
# lower() function to convert
# string to lower_case
print("\nConverted String:")
print(text.lower())


Output: 

Original String:
GeEks FOR geeKS
Converted String:
geeks for geeks

String with alphanumeric characters

In this example, the String with Alphanumeric Characters and code defines a string variable ‘text’ with a mixed case. It then prints the original string and, in the next section, prints the string converted to lowercase using the lower() function.

Python3




text = 'G3Ek5 F0R gE3K5'
 
print("Original String:")
print(text)
 
# lower() function to convert
# string to lower_case
print("\nConverted String:")
print(text.lower())


Output: 

Original String:
G3Ek5 F0R gE3K5
Converted String:
g3ek5 f0r ge3k5

Other Methods to Convert String to Lower Case

Let’s look at some other methods to convert a string to lowercase. There are multiple ways to complete a task in Python and we will discuss some lower() method alternatives below:

Convert String to lowercase using map With Lambda Function

In this example, the code converts the string “GeeksForGeeks” to lowercase using a lambda function and the map function. The result, “geeksforgeeks,” is then printed. The same can be achieved more succinctly with `lowercased_string = original_string.lower()`.

Python3




original_string = "GeeksForGeeks"
lowercased_string = ''.join(map(lambda x: x.lower(), original_string))
print(lowercased_string)


Output:

geeksforgeeks

Convert String to lowercase using List Join

In this example, the code converts the string “Pratham Sahani” to lowercase using a list comprehension. The resulting lowercase string is then joined and printed.

Python3




original_string = "Pratham Sahani"
lowercased_string = ''.join([c.lower() for c in original_string])
print(lowercased_string)


Output :

pratham sahani

Convert String to lowercase using map and str.lower with lower() Method

In this example, the code converts the original string “GeeksforGeeks” to lowercase characters using the str.lower method. However, the map function needs to be wrapped in a list() or join() to apply the transformation to each character.

Python3




original_string = "GeeksforGeeks"
lowercased_string = ''.join(map(str.lower, original_string))
print(lowercased_string)


Output :

geeksforgeeks

Convert String to lowercase using Swapcase() Function

Convert uppercase to lowercase in Python using the swapcase() function. In this example, code defines a string ‘GEEKSFORGEEKS’ in variable ‘s’. The `swapcase()` method is then applied to the string, converting uppercase letters to lowercase and vice versa.

Python3




s = 'GEEKSFORGEEKS'
print(s.swapcase())


Output:

geeksforgeeks

Convert String to lowercase using casefold() Function

Convert uppercase to lowercase in Python using the casefold function. In this example code converts the string ‘GEEKSFORGEEKS’ to its casefolded form, making it lowercase and suitable for case-insensitive comparisons.

Python3




s = 'GEEKSFORGEEKS'
print(s.casefold())


Output:

geeksforgeeks

Applications of String lower() method

Let’s look at some other uses of the string lower() method in Python. It can be used in other ways, depending on your creativity. We have mentioned one such use of the Python lower() method.

Comparison of Strings using lower() Method

One of the common applications of the lower() method is to check if the two strings are the same or not. In this example, the code compares two strings, `text1` and `text2`, after converting them to lowercase using the `lower()` method. If the lowercase versions of the strings are equal, it prints “Strings are same”; otherwise, it prints “Strings are not same.”

Python3




text1 = 'GEeKS foR GeeKs'
text2 = 'gEeKS fOR GeeKs'
 
# Comparison of strings using
# lower() method
if(text1.lower() == text2.lower()):
    print("Strings are same")
else:
    print("Strings are not same")


Output: 

Strings are same

We have discussed how to use the lower() method to convert a string to lowercase and also discussed some other ways to perform the same task. The techniques are explained through a program as an example for a better understanding of methods.

You can also check other string methods

Read more related content on the Python Lower Method:



Last Updated : 05 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads