.lower()
Anonymous contributor
Published Jun 7, 2021Updated Aug 15, 2023
Contribute to Docs
Takes a string, and returns a copy of that string in which all letters are lowercase. Numbers and symbols are not changed.
Syntax
string.lower()
Example 1
The .lower()
method can be used to compare strings:
string1 = "Red Pandas"string2 = "rEd pAnDaS"if string1 == string2:print("These strings are already the same")elif string1.lower() == string2.lower():print("They are the same when you use the .lower() method")else:print("They are NOT the same")# Output: They are the same when you use .lower()
Example 2
The .lower()
method can be used to standardize text that might take different forms, such as user input or the response to an API call:
name = input("What is your name?")# User writes their name...if name.lower() == "codey":print("Your name is Codey!")else:print("Your name is not Codey.")
This would print Your name is Codey!
whether the user typed in Codey
, codey
, CODEY
, or CoDeY
.
Example 3
The .lower()
method does not change the string it is used on:
my_string = "AMAZING!"if my_string.lower() == "amazing!":print("Isn't that just " + my_string)# Output: "Isn't that just AMAZING!""
Codebyte Example
The example below compares color_entry_a
to color_entry_b
using .lower()
. Note color_entry_a
remains capitalized even after the .lower()
method is used on it.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Skill path
Analyze Data with Python
Learn to analyze and visualize data using Python and statistics.Includes 8 CoursesWith CertificateIntermediate13 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours