.lower()

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.

Code
Output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy