How do I uppercase or lowercase a string in Python?

Better Stack Team
Updated on January 26, 2023

To uppercase a string in Python, you can use the upper() method of the string. For example:

 
string = "hello"
uppercase_string = string.upper()
print(uppercase_string)  # prints "HELLO"

To lowercase a string in Python, you can use the lower() method of the string. For example:

 
string = "HELLO"
lowercase_string = string.lower()
print(lowercase_string)  # prints "hello"

Both upper() and lower() are string methods, so they can be called on any string object in Python. They do not modify the original string, but instead return a new string with the uppercase or lowercase version of the original string.