String lower() Method in Python

Python String lower() Method

In Python, the lower() method is a built-in string method that converts all the characters in a string to lowercase. It returns a new string with all the uppercase characters converted to lowercase while leaving the lowercase characters unchanged.

Here's the syntax of the lower() method:

string.lower()

where string is the original string that you want to convert to lowercase.

Here are some examples to illustrate how the lower() method works:

# Example 1:
original_string = "Hello, World!"
lowercased_string = original_string.lower()
print(lowercased_string)
# Output: "hello, world!"

# Example 2:
name = "John Doe"
lowercased_name = name.lower()
print(lowercased_name)
# Output: "john doe"

# Example 3:
mixed_case = "PyTHon iS Fun"
lowercased_mixed_case = mixed_case.lower()
print(lowercased_mixed_case)
# Output: "python is fun"

It's important to note that the lower() method does not modify the original string but returns a new string with all characters converted to lowercase. If you want to change the original string in-place, you can assign the result back to the original variable:

string = "HELLO, PYTHON!"
string = string.lower()
print(string)
# Output: "hello, python!"

This way, the string variable will now hold the lowercase version of the original string.