Signup/Sign In
JUNE 29, 2023

Lowercase a String in Python

    While working with a string in Python, you may want to convert the contents of that string into lowercase. Talking about a very common example which everyone can understand very easily is the sign-up forms that we go on filling then and now, in which the e-mail field is compulsorily required in lowercase, even if you enter it in uppercase either it gets converted in lowercase or shows an error because that field is case-sensitive.

    In this article, we will discuss various ways to lowercase a string in Python.

    String Lowercase

    The Python language has a built-in function lower() which can be used to convert uppercase strings into lowercase and return the string into latter form.

    This method converts all the characters of the string into lowercase, leaving the numbers and special characters unchanged. It is added to the end of a Python String Value.

    Here is the syntax declaration of the Python lower() method, this method does not take any parameter, and it returns all the lowercased string from the given uppercase string.

    If no uppercase character is found, it returns the original string.

    String_name.lower()

    Example 1

    # Example String
    string = "STUDY TONIGHT"
    print(string.lower())
    
    # Example String with numbers
    
    string = "ST!UDY TO2NIGHT"
    print(string.lower())
    
    


    study tonight
    st!udy to2night

    Example 2

    # first string
    firstString = "STUDY TONIGHT IS COOL!"
    
    # second string
    secondString = "STuDY TOniGHT iS CoOl!"
    
    if(firstString.lower() == secondString.lower()):
        print("The strings are same.")
    else:
        print("The strings are not same.")


    The strings are same.

    Python islower() method:

    The islower() method in Python checks whether the given already has lowercase characters in it or not. Similar to lower() method, it does not evaluate numbers, spaces, and special characters.

    This method helps us in case if we want to make sure that the string we are going to convert into lowercase, is already in lowercase or not.

    Below is the syntax declaration of this method. Like the lower() method, it also does not accept any parameter. It returns boolean true if the given string contains lowercase characters, otherwise, it returns false.

    string_name.islower()

    Example 3

    str_check = "study tonight"
    str_out = str_check.islower()
    print(str_out)
    str_check1 = "STUDY TONIGHT"
    str_out1 = str_check1.islower()
    print(str_out1)


    True
    False

    Example 4

    str = "study tONIGHT"
    str_out = str.lower()
    print("The string converted in lowercase is:")
    print(str_out)
    print("\nTo check if the string is converted to lowercase")
    str_check = str_out.islower()
    if str_check is True:
    print("Yes the string is in lowercase.")
    else:
    print("No the string is not converterd into lowercase")


    The string converter in lowercase is:
    study tonight

    To check if the string is converted to lowercase
    Yes the string is in lowercase.

    Conclusion

    In this article, we discussed two Python lowercase methods lower() and islower() with the help of few examples, we learned that lower() method is used to convert the uppercase characters into lowercase and return the same, and islower() method is used to validate whether the given string is already in lowercase or not. Keep in mind that both of these methods do not apply to alphabets and special symbols. We hope that this tutorial helped you in some way or another. Cheers!

    I am the founder of Studytonight & Fullstack developer (MERN). I like writing content about ReactJS, MERN, JavaScript, Docker, Linux, PHP, Go lang, Cloud, Web development, and general Tech related content. I have 10 years of diverse experience in software development.
    IF YOU LIKE IT, THEN SHARE IT
    Advertisement

    RELATED POSTS