Python String lower() Tutorial

Python provides string type where uppercase and lowercase letters or characters can be used. There are different methods in order to manipulate the string where the lower() method is used to make all letters lowercase. If the character is uppercase it will be converted into the lowercase if the character is lowercase there will be no change.

lower() Method Syntax

The lower() method has very simple syntax where it returns the lowercase version of the specified string. As a built-in method, there is no need to import an extra module.

STRING.lower()
  • STRING is the string variable or string literal which will be made lowercase.

Make String Variable Lowercase

In the following example we will convert a string variable into the lowercase. All the letters will be converted into the lowercase with the lower() method.

sentence1 = "I Like PythonTect"
lowercase_sentence1= sentence1.lower()
print(lowercase_sentence1)


sentence2 = "I Like 33 PythonTect"
lowercase_sentence2= sentence2.lower()
print(lowercase_sentence2)

Output is like below as the numbers do not have lowercase they will not changed.

i like pythontect
i like 33 pythontect

Make String Literal Lowercase

String literals are also a string type but difference is that they are not stored inside a variable. But they are string too and butil-in string methods like lower() can be also called over these string literals.

lowercase_sentence1= "I Like PythonTect".lower()
print(lowercase_sentence1)

lowercase_sentence2= "I Like 33 PythonTect".lower()
print(lowercase_sentence2)

Output is like below which is the same with string variables as the numbers do not have lowercase they will not changed.

i like pythontect
i like 33 pythontect

Check If Given String Is Lowercase

The lower() method can be also used to make some checks for provided or input strings by using if..else statements. In the following example, we will use the lower() method to lower all given sentences and check if they are the same. We can also use string literals to make the lowercase and then check.

sentence1 = "I Like PythonTect"

sentence2 = "I LIKE PYTHONTECT"

if(sentence1.lower() == sentence2.lower()):
   print("The sentences are the same")
else:
   print("The sentences are NOT the same")


if(sentence1.lower() == "I LIKE PYTHONTECT".lower()):
   print("The sentences are the same")
else:
   print("The sentences are NOT the same")

The output will be like below.

The sentences are the same
The sentences are the same

Leave a Comment