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

How to Convert Strings to Lowercase in Python?

Susan Sarandon
Susan SarandonOriginal
2024-11-16 10:08:02697browse

How to Convert Strings to Lowercase in Python?

Converting Strings to Lowercase in Python

Lowercasing a string involves changing all uppercase characters to their corresponding lowercase counterparts. In Python, there's a convenient method to perform this operation: str.lower().

Syntax:

string.lower()

Function:

Converts the given string to lowercase.

Example:

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

This method preserves special characters, numbers, and whitespace, as seen below:

>>> "123 SPECIAL CHARACTERS".lower()
'123 special characters'

Note:

Unlike some other programming languages, Python does not have a built-in function to directly uppercase a string. Instead, you can use the str.upper() method in conjunction with str.lower():

>>> string = "KILOMETERS"
>>> string = string.upper().lower()
>>> print(string)  # Output: 'kilometers'

The above is the detailed content of How to Convert Strings 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