Open In App

Python String lower() Method

Last Updated : 05 Jan, 2024
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:



Previous Article
Next Article

Similar Reads

Python String Methods | Set 1 (find, rfind, startwith, endwith, islower, isupper, lower, upper, swapcase & title)
Some of the string basics have been covered in the below articles Strings Part-1 Strings Part-2 The important string methods will be discussed in this article1. find("string", beg, end) :- This function is used to find the position of the substring within a string.It takes 3 arguments, substring , starting index( by default 0) and ending index( by
4 min read
numpy string operations | lower() function
numpy.core.defchararray.lower(arr) function is used to return an array with the elements converted to lowercase. Parameters: arr : [ array_like ] Input array which may be str or unicode. Returns : [ndarray] Output lowercased array of str or unicode, depending on input type. Code #1: # Python Program explaining # numpy.char.lower() function import n
1 min read
PyQt5 - lower() method for Labels
In PyQt5, when we create more than one label at same position they overlap each other such that the label which was made at last should be shown at top. Although, we can set the opaque level but sometimes some label have lower priority and that's why they should be at below level therefore, lower() method is used. Syntax : label.lower() Argument :
2 min read
Integrate Legendre series and set the lower bound of the integral using NumPy in Python
In this article, we will see how to integrate a Legendre series and set the lower bound of the integral in Python using NumPy. To perform Legendre integration, NumPy provides a function called legendre.legint which can be used to integrate Legendre series. Syntax: legendre.legint(c, lbnd=0, scl=1, axis=0) Parameters: c – Array of Legendre series co
2 min read
Python program to count upper and lower case characters without using inbuilt functions
Given a string that contains both upper and lower case characters in it. The task is to count a number of upper and lower case characters in it. Examples :Input : Introduction to Python Output : Lower Case characters : 18 Upper case characters : 2 Input : Welcome to GeeksforGeeks Output : Lower Case characters : 19 Upper case characters: 3Method 1:
3 min read
Python | Pandas Series.str.lower(), upper() and title()
Python is a great language for data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages, making importing and analyzing data much easier. Python has some inbuilt methods to convert a string into a lower, upper, or Camel case. But these methods don't work on lists and other multi-st
4 min read
Python regex to find sequences of one upper case letter followed by lower case letters
Write a Python Program to find sequences of one upper case letter followed by lower case letters. If found, print 'Yes', otherwise 'No'. Examples: Input : GeeksOutput : YesInput : geeksforgeeksOutput : NoPython regex to find sequences of one upper case letter followed by lower case lettersUsing re.search() To check if the sequence of one upper case
2 min read
Python - Custom Lower bound a List
Given a list, assign a custom lower-bound value to it. Input : test_list = [5, 7, 8, 2, 3, 5, 1], K = 3 Output : [5, 7, 8, 3, 3, 5, 3] Explanation : All elements less than 3, assigned 3. Input : test_list = [5, 7, 8, 2, 3, 5, 1], K = 5 Output : [5, 7, 8, 5, 5, 5, 5] Explanation : All elements less than 5, assigned 5. Method #1: Using list comprehen
2 min read
Python Program Integrate a Chebyshev Series and Set the Lower Bound of the Integral
The Chebyshev series has polynomials with the largest possible leading coefficient, whose absolute value on the interval [−1, 1] is bounded by 1. They are also the "extremal" polynomials. Chebyshev polynomials are significant in approximation theory because the roots of Tn(x), which are also called Chebyshev nodes, are used as matching points for o
3 min read
Python Program to check if matrix is lower triangular
Given a square matrix and the task is to check the matrix is in lower triangular form or not. A square matrix is called lower triangular if all the entries above the main diagonal are zero. Examples: Input : mat[4][4] = {{1, 0, 0, 0}, {1, 4, 0, 0}, {4, 6, 2, 0}, {0, 4, 7, 6}};Output : Matrix is in lower triangular form.Input : mat[4][4] = {{1, 0, 0
2 min read
Practice Tags :
three90RightbarBannerImg