Takes a string, and returns a copy of that string in which all letters are lowercase. Numbers and symbols are not changed.
.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()
.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
.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!""
The example below compares
color_entry_a remains capitalized even after the
.lower() method is used on it.
- christian.dinh2481 total contributions
- Anonymous contributorAnonymous contributor3077 total contributions
- CyberRedPanda27 total contributions