Python str.lower() function
str.lower()
Function in Python
The str.lower()
function in Python is used to convert all uppercase letters in a string to lowercase. Non-alphabetical characters (such as digits, punctuation, and spaces) remain unaffected.
Syntax:
string
: The string that you want to convert to lowercase.
Example:
In this example:
- The string
"HELLO, WORLD!"
is converted to"hello, world!"
. - Only the uppercase letters are converted to lowercase, while punctuation and spaces are unaffected.
Example with mixed case:
Here, the uppercase letters in "Python Is Fun!"
are converted to lowercase, and other characters (like spaces and punctuation) remain unchanged.
Example with numbers and special characters:
In this case:
- The digits (
123
) and special characters (!@#
) are not affected. - The uppercase letters (
ABC
) are converted to lowercase (abc
).
Key Points:
str.lower()
affects only alphabetic characters and converts them to lowercase.- It does not modify the original string but returns a new string with the converted characters.
- Non-alphabetic characters like numbers, punctuation, and spaces remain unchanged.