How to convert a string to lowercase in Python
How to convert a string to lowercase in Python.
Here is a step-by-step tutorial on how to convert a string to lowercase in Python:
Step 1: Start by defining a string that you want to convert to lowercase. For example, let's say our string is "Hello World".
Step 2: Use the lower() method on the string to convert it to lowercase. The lower() method is a built-in function in Python that returns a lowercase version of the string. Assign the result to a new variable or print it directly.
Here is an example code snippet:
string = "Hello World"
lowercase_string = string.lower()
print(lowercase_string)
Output:
hello world
In this example, we assigned the lowercase version of the string to the variable lowercase_string
and then printed it.
Alternatively, you can directly print the lowercase version without assigning it to a variable:
string = "Hello World"
print(string.lower())
Output:
hello world
This approach directly converts the string to lowercase and prints it without storing it in a separate variable.
That's it! You have successfully converted a string to lowercase in Python using the lower()
method.