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

How to Convert Strings to Lowercase in Python?

Susan Sarandon
Release: 2024-11-16 10:08:02
Original
696 people have browsed it

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'
Copy after login

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

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

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'
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template