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.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

We are hiring.

Software is our way of making the world a tiny bit better. We build tools for the makers of tomorrow.

Explore all positions →

Reliability is the
ultimate feature

Delightful observability tools that turn your logs & monitoring into a secret weapon for shipping better software faster.

Explore Better Stack