In python, the built-in string function lower()
is used to convert a string to lowercase. It converts all uppercase characters in a string to lowercase and returns it.
s = "THIS IS SPARTA!" print(s.lower())
Output:
this is sparta!
Table of Contents
- Syntax
- Examples
- How to check if a python string is lowercase or not?
Syntax
The following is the syntax for using the string lower()
function:
string.lower()
Parameters:
The string lower function does not take any parameters.
Returns:
Introductory ⭐
- Harvard University Data Science: Learn R Basics for Data Science
- Standford University Data Science: Introduction to Machine Learning
- UC Davis Data Science: Learn SQL Basics for Data Science
- IBM Data Science: Professional Certificate in Data Science
- IBM Data Analysis: Professional Certificate in Data Analytics
- Google Data Analysis: Professional Certificate in Data Analytics
- IBM Data Science: Professional Certificate in Python Data Science
- IBM Data Engineering Fundamentals: Python Basics for Data Science
Intermediate ⭐⭐⭐
- Harvard University Learning Python for Data Science: Introduction to Data Science with Python
- Harvard University Computer Science Courses: Using Python for Research
- IBM Python Data Science: Visualizing Data with Python
- DeepLearning.AI Data Science and Machine Learning: Deep Learning Specialization
Advanced ⭐⭐⭐⭐⭐
- UC San Diego Data Science: Python for Data Science
- UC San Diego Data Science: Probability and Statistics in Data Science using Python
- Google Data Analysis: Professional Certificate in Advanced Data Analytics
- MIT Statistics and Data Science: Machine Learning with Python - from Linear Models to Deep Learning
- MIT Statistics and Data Science: MicroMasters® Program in Statistics and Data Science
🔎 Find Data Science Programs 👨💻 111,889 already enrolled
Disclaimer: Data Science Parichay is reader supported. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. Earned commissions help support this website and its team of writers.
A string with all the cased characters converted to lowercase.
Examples
Example 1: Convert string with a mix of lowercase and uppercase characters to lowercase.
s = "tHiS iS sPArTa!" # original string print("Original String: ", s) # after converting to lowercase s_lower = s.lower() print("After Converting:", s_lower)
Output:
Original String: tHiS iS sPArTa! After Converting: this is sparta!
In the above example, all the uppercase characters have been converted to lowercase while the lowercase characters and non-cased characters remain unchanged.
Example 2: Convert string without any alphabetical character to lowercase.
s = "123 #$% <>!?" # original string print("Original String: ", s) # after converting to lowercase s_lower = s.upper() print("After Converting:", s_lower)
Output:
Original String: 123 #$% <>!? After Converting: 123 #$% <>!?
In the above example, since the string did not have any cased characters (that is, characters associated with a case like lowercase, uppercase, or titlecase) we get the same string without any changes on applying the lower()
function.
Example 3: Using the python string lowercase function to match strings.
Often it’s required to check if two strings are the same irrespective of their case. For example, you have the names of all your leads collected via a form on your website, and its quite possible that many of them didn’t use a style convention like using titlecase (e.g. John Doe
), some may have filled it in all lower or all uppercase as well. In such a scenario, you can match the two strings by converting both to either upper, lower, or titlecase.
# matching strings # list of names ls = ["Bruce Banner", "peter Parkar", "STEVE RODERS"] # name to match for name = "Peter Parkar" # check whether the name is present in the list for l in ls: # match for the name if l.lower() == name.lower(): print("Match found for", name)
Output:
Match found for Peter Parkar
In the above example, we check whether a name is present in a list irrespective of the case of the strings.
How to check if a python string is lowercase or not?
We can check whether a string is lowercase or not using the islower()
function. It’s a string function that returns True
if all the cased characters in the string are in lowercase. If the string does not contain any cased characters or any of the cased characters are not lowercase then it returns False
.
Example:
s = "this is sparta!" print(s.islower())
Output:
True
In the above example, since all the cased characters are in lowercase the islower()
function returns True
.
For more, refer to python string methods docs.
Other articles on python strings:
- Python String Uppercase – With Examples
- Python String Split – With Examples
- Python String Join – With Examples
- Python String Concatenation – With Examples
- Python String Replace – With Examples
Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.