Use lower() Function in Python with Example

The `lower()` function in Python is used to convert all the characters in a string to lowercase. It returns a new string with all characters converted to lowercase.

Syntax

string.lower()
string: The string you want to convert to lowercase.

Example

# Original string
original_string = "Hello, WORLD!"
# Convert to lowercase
lowercase_string = original_string.lower()
print("Original String:", original_string)
print("Lowercase String:", lowercase_string)

Output

Original String: Hello, WORLD!
Lowercase String: hello, world!

Explanation

– In this example, the original string `”Hello, WORLD!”` contains a mix of uppercase and lowercase letters.
– The `lower()` function converts all the characters to lowercase, resulting in `”hello, world!”`.
– The original string remains unchanged since `lower()` returns a new string rather than modifying the original one.

The `lower()` function is useful when you need to standardize the case of strings for comparison, search operations, or other text processing tasks.