PythonString methods
str. lower()
Returns a copy of the string written in lowercase letters.
- Returns
- A new string in lowercase.
- Changes the original
- No
Example
#Python
answer = " YES "
if answer.strip().lower() == "yes":
print("Answer saved")
email = "Emma.Smith@CodeWorlds.COM"
print(email.lower())Resultsaved result, you can check it
Answer saved
emma.smith@codeworlds.com
Definition and usage
#The lower() method returns a new string with every letter converted to lowercase. Like other string methods, it does not change the original.
The most common use is normalizing user input before comparing it: the answers "YES", "Yes", and "yes" all look the same after lower().
For comparing text across languages, the casefold() method is safer. For example, it converts the German ß into ss.
Syntax
#Syntax
string.lower()Good practices
#- Convert email addresses to lowercase before saving and comparing them.
- Combine
strip()andlower()when handling text typed by a user.
Related entries
#Spotted a mistake or missing an example? Write to us.