Methods and Functions

Python String lower()

TheIn Python, there are various built-in methods that allow us to easily modify strings. When working with a string in Python, you may want to convert the string to lowercase or check if the string is already in a lowercase state. For example, you could be designing a sign-up form that transforms a user’s email address to lowercase. This is where the Python lower() string function comes in handy. The lower() method converts all case-sensitive characters in a string to lowercase. This article will explain how to use this built-in function to work with lowercase strings. We’ll also go over a few examples to show how they work.

Python lower() function

Definition

  • Python lower() function is an inbuilt string class method that converts all the uppercase characters in the string into lowercase characters and returns a new string.
  • The Python lower() string method returns a string copy with all the characters changed to lowercase. The original string is not altered by this procedure.

Python lower()

Python lower() is a built-in string handling technique. lower() function in Python can be used to transform all case-based characters in a string to lowercase. The lower() method returns a duplicate of an original string with all characters in lowercase. The lower() function also ignores any numerals, special characters, or lowercase letters in the supplied string.

lower() Syntax

The syntax followed by Python’s lower() function is as follows:

                    

string.lower()

lower() Parameters

The lower() string function does not accept any parameters and it is appended to the end of a string value that already exists.

Note – If any parameter is passed, the function throws an exception error.

Return value from lower()

Python lower() returns the lowercase string from a provided string. All uppercase characters are converted to lowercase. If no uppercase characters are found, the original string is returned.

Example 1: Convert a string to uppercase

Example

                    

# Python program to illustrate lower()
txt = 'GOOD MORNING, EVERYONE'
print(txt.lower())

txt = 'WELCOME Home Jimmy'
print(txt.lower())

txt = 'Mobile No - 9341239145'
print(txt.lower())

txt = 'hello'
print(txt.lower())

Output

                    

good morning, everyone
welcome home jimmy
mobile no - 9341239145
hello

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

Example

                    

# To check if strings are equal
str1 = 'i love cars'
str2 = 'I LoVe CarS'

if(str1.lower() == str2.lower()):
     print('Both the strings are same')
else:
     print('Both the strings are different')

Output

                    

Both the strings are same

Difference between lower(), islower(), and swapcase()

  • Python lower() – The lower() method converts all the uppercase characters to lowercase.
  • Python islower() – This function returns True if all the values in the input string are in lowercase, else it returns False.
  • The Python swapcase() – The swapcase() method returns a string with all the uppercase characters converted to lowercase and all the lowercase characters converted to uppercase.

Example

                    

txt = 'Do You WatCh Tv?'

# converts all to lowercase
print(txt.lower())
# converts uppercase to lowercase and vice versa
print(txt.swapcase())
# returns Boolean value
print(txt.islower())

Output

                    

do you watch tv?
dO yOU wATcH tV?
False

Frequently Asked Questions

Q1. What is lowercase in Python?

Lowercase is defined as something written or printed in small letters (i.e. a-z). To convert any character into lowercase in Python, we use the built-in lower() function. Python lower() function is an inbuilt string class method that converts all the uppercase characters in the string into lowercase characters and returns a new string.

Q2. How do you lowercase all letters in Python?

To convert all the string characters to lowercase, we use the Python lower() function. lower() function in Python can be used to transform all case-based characters in a string to lowercase. The lower() method returns a duplicate of an original string with all characters in lowercase

The syntax followed by Python’s lower() function is as follows:

                    

string.lower()

Example

                    

txt = 'Egg Bread Cheese Apple Orange'
print(txt.lower())

txt = 'I love my Country'
print(txt.lower())

txt = 'python programming 101'
print(txt.lower())

Output

                    

egg bread cheese apple orange
i love my country
python programming 101

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

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

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.