Home >Backend Development >Python Tutorial >How to Convert a String to Lowercase in Python?

How to Convert a String to Lowercase in Python?

Susan Sarandon
Susan SarandonOriginal
2024-11-14 21:02:02760browse

How to Convert a String to Lowercase in Python?

Lowercasing Strings in Python

Python offers a straightforward method to convert strings to lowercase format. This is particularly useful when you need to standardize text or ensure case-insensitive processing.

How to Lowercase a String?

To convert a string to lowercase, simply utilize the str.lower() method. This method operates on a string and returns a lowercase copy of it.

For instance:

>>> text = "KiLoMeTeRs"
>>> text.lower()
'kilometers'

Example:

Let's consider the string "Kilometers". Using the str.lower() method, we can convert it to lowercase:

>>> "Kilometers".lower()
'kilometers'

As you can see, the string has been transformed into all lowercase characters.

Additional Notes:

  • The original string remains unchanged. The str.lower() method creates a new string in lowercase.
  • This method can also be applied to Unicode strings.
  • For the opposite operation of converting a string to uppercase, refer to the guide: "How to change a string into uppercase?".

The above is the detailed content of How to Convert a String to Lowercase in Python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn