Home > Article > Backend Development > 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!