In the previous article, we have discussed Python String index() Method with Examples
String lower() Method in Python:
lower() returns a string with all characters in lower case.
Symbols and numbers are not accepted.
Syntax:
string.lower()
Parameter Values: This method has no parameters.
Return Value:
lower() returns the lowercase string from a given string. It converts all uppercase to lowercase characters.
If no uppercase characters are found, the original string is returned.
Examples:
Example1:
Input:
Given String = "HELLO this IS Btechgeeks"
Output:
The given original string : HELLO this IS Btechgeeks The given string after applying lower() method : hello this is btechgeeks
Example2:
Input:
Given String = "GooD MORNING btechgeeks@123$$#"
Output:
The given original string : GooD MORNING btechgeeks@123$$# The given string after applying lower() method : good morning btechgeeks@123$$#
String lower() Method with Examples in Python
Method #1: Using Built-in Functions (Static Input)
Approach:
- Give the string as static input and store it in a variable.
- Apply the lower() method to the given string that returns a string with all characters in lower case.
- Store it in another variable.
- Print the given original string.
- Print the given string after applying the lower() method.
- The Exit of the program.
Below is the implementation:
# Give the string as static input and store it in a variable.
gvn_str = "HELLO this IS Btechgeeks"
# Apply lower() method to the given string that returns a string with all characters
# in lower case.
# Store it in another variable.
rslt = gvn_str.lower()
# Print the given original string.
print("The given original string :", gvn_str)
# Print the given string after applying the lower() method.
print("The given string after applying lower() method :")
print(rslt)
Output:
The given original string : HELLO this IS Btechgeeks The given string after applying lower() method : hello this is btechgeeks
How does lower() function work in a program?
Approach:
- Give the first string as static input and store it in a variable.
- Give the second string as static input and store it in another variable.
- Converting both the given first and second strings into lowercase using the lower() method and checking if both the strings are the same or not using the if conditional statement.
- If it is true, then print “The given first and second strings are same”.
- Else print “The given first and second strings are NOT same”.
- The Exit of the program.
Below is the implementation:
# Give the first string as static input and store it in a variable.
gvn_fststr = "WELCOME to PythoN PROGRAMS"
# Give the second string as static input and store it in a variable.
gvn_scndstr = "Welcome to Python programs"
# Converting both the first and second strings into lowercase using the lower()
# method and checking if both the strings are same or not using the if conditional
# statement.
if(gvn_fststr.lower() == gvn_scndstr.lower()):
# If it is true, then print "The given first and second strings are same".
print("The given first and second strings are same")
else:
# Else print "The given first and second strings are NOT same".
print("The given first and second strings are NOT same")
Output:
The given first and second strings are same
Method #2: Using Built-in Functions (User Input)
Approach:
- Give the string as user input using the input() function and store it in a variable.
- Apply lower() method to the given string returns a string with all characters in lower case.
- Store it in another variable.
- Print the given original string.
- Print the given string after applying the lower() method.
- The Exit of the program.
Below is the implementation:
# Give the string as user input using the input() function and store it in a variable.
gvn_str = input("Enter some Random String = ")
# Apply lower() method to the given string that returns a string with all characters
# in lower case.
# Store it in another variable.
rslt = gvn_str.lower()
# Print the given original string.
print("The given original string :", gvn_str)
# Print the given string after applying the lower() method.
print("The given string after applying lower() method :")
print(rslt)
Output:
Enter some Random String = GooD MORNING btechgeeks@123$$# The given original string : GooD MORNING btechgeeks@123$$# The given string after applying lower() method : good morning btechgeeks@123$$#
Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.