How to Convert a String to Lowercase in Python?

In this tutorial, I will explain how to convert a string to lowercase in Python. As a Python developer, I often encounter situations where I need to modify the case of a string. After research, I found three efficient methods to achieve this task. Let us learn more about this topic.

Convert a String to Lowercase in Python

Let us learn some efficient methods of converting a string to lowercase in Python.

Read How to Split String by Whitespace in Python?

1. Use lower() Method

Python lower() method converts all the characters in a string to lowercase, making it useful for standardizing text.

text = "USA"
result = text.lower()
print(result) 

Output:

usa

I have executed the above example code and added the screenshot below.

Convert a String to Lowercase in Python

The lower() method is essential when converting a string entirely to lowercase, ensuring consistency across your text. It’s particularly useful for case-insensitive comparisons or normalizing text for further processing.

Check out How to Repeat a String Multiple Times in Python?

2. Use swapcase() Method

The swapcase() method changes the case of each character in the string. Uppercase letters become lowercase, and lowercase letters become uppercase.

text = "USA"
result = text.swapcase()
print(result) 

Output:

usa

I have executed the above example code and added the screenshot below.

How to Convert a String to Lowercase in Python

The swapcase() method is a fun and practical way to invert the case of each character in a string. It’s handy for text transformations where alternating letter cases are needed, such as in text formatting or creating stylized outputs.

Read How to Convert Datetime to String in Python?

3. Use casefold() Method

The loThe casefold() method is a more aggressive version of lower() and is used for case-insensitive comparisons, especially when dealing with different languages.

text = "USA"
result = text.casefold()
print(result)  

Output:

usa

I have executed the above example code and added the screenshot below.

Convert a String to Lowercase in Python casefold()

The casefold() method goes a step further than lower() , providing a more robust solution for case-insensitive string comparisons, particularly when dealing with different languages and special characters.

Read How to Check if a String is a Valid UUID in Python?

Conclusion

In this tutorial, I have explained how to convert a string to lowercase in Python. I have explained three main methods to achieve this task such as, lower() method, swapcase() method, casefold() method.

You may also like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.