in

Python To Lowercase

python-to-lowercase

the string lower () returns all the words in your string by changing them python to the lowercase

The syntax of lower() method is:

string.lower()

String lower() Parameters()

lower () the method doesn’t take any parameters.

Return value from String lower()

The lower () the method returns a string of lowercase words from your given string and converts all capital words or letters into python to lowercase.

If there are no capital letters in your string, it gives you the same string as the original string.

Example 1: Convert a string to lowercase

# example string
string = "PYTHON TO LOWERCASE!"
print(string.lower())

# string with numbers
# all alphabets whould be lowercase
string = "Pyth0n T0 L0w3rCas3!"
print(string.lower())

Output:

python to lowercase!
pyth0n t0 l0w3rcas3!

Example 2: How lower() is used in a program?

# first string
firstString = "PYTHON IS AWESOME!"

# second string
secondString = "PyThOn Is AwEsOmE!"

if(firstString.lower() == secondString.lower()):
    print("The strings are same.")
else:
    print("The strings are not same.")

Output:

The strings are same.

Note: If you want to convert to uppercase string, use upper(). You can also use swapcase() to swap between lowercase to uppercase.

Leave a Reply

Your email address will not be published. Required fields are marked *

python-absolute-value

Python Absolute Value