Skip to content
Foxipa
How-topython

How to Convert Uppercase to Lowercase and Lowercase to Uppercase in Python

Learn how to convert Python strings to lowercase, uppercase, or swap their existing letter case with lower(), upper(), and swapcase().

Levels: Beginner ~8 min read

At a glance

Before you begin

Goal

Convert Python strings to lowercase, uppercase, or the opposite case using the standard string methods.

You'll need

  • Basic familiarity with Python strings and variables
  • A Python environment, or the runnable example on this page

Outcome

You can choose between lower(), upper(), and swapcase() for common text case-conversion tasks, including text read from input().

Applies to

  • Python — 3.x — Any

The three methods to remember

  • Use lower() to convert cased characters to lowercase.
  • Use upper() to convert cased characters to uppercase.
  • Use swapcase() when you want uppercase letters to become lowercase and lowercase letters to become uppercase in the same operation.

1. Convert a string to lowercase

Call lower() on a string when you want its cased characters converted to lowercase. The method returns a new string; it does not change the original string in place.

python
text = "Hello, PYTHON!"
lowercase_text = text.lower()

print(lowercase_text)
print(text)

The output is hello, python! followed by the original Hello, PYTHON!. Python strings are immutable, so the converted value must be stored or used directly.

2. Convert a string to uppercase

Call upper() to convert the string's cased characters to uppercase.

python
text = "Hello, Python!"
uppercase_text = text.upper()

print(uppercase_text)

3. Convert both directions at once with swapcase()

If the requirement is specifically to reverse the existing case, use swapcase(). Uppercase characters become lowercase, and lowercase characters become uppercase.

python
text = "Hello, PyTHON!"
converted = text.swapcase()

print(converted)

4. Convert text entered by a user

The same methods work on strings returned by input(). This is useful when a program needs to normalize text before displaying it, comparing it, or storing it.

Interactive Runnable example
Edit

Ready to run.

5. Choose the method that matches the job

  1. Use lower() when the desired result is all lowercase.

  2. Use upper() when the desired result is all uppercase.

  3. Use swapcase() when each cased character should switch to the opposite case.

6. Case conversion and Unicode text

Python's string case methods are defined for Unicode text, not just the English alphabet. That matters when your application handles names or text in other languages.

python
text = "Straße"

print(text.lower())
print(text.upper())
print(text.casefold())

Notice that casefold() is not simply another spelling of lower(). It is designed for caseless matching and can make more aggressive Unicode case transformations. Use it when you are comparing text without regard to case rather than when you merely want to display lowercase text.

Common mistakes

  • Forgetting the parentheses: text.lower refers to the method, while text.lower() calls it.

  • Expecting the original string to change: assign the returned value if you need to keep the converted text.

  • Using swapcase() for normalization: choose lower() or upper() when the target case is fixed.

Reference

For the exact behavior and Unicode rules, see Python's official documentation for the str.lower(), str.upper(), str.swapcase(), and str.casefold() methods.

Once these methods are familiar, you can combine them with Python's string operations to build reliable text-processing routines.

Found an issue?

Help keep this guide accurate by suggesting an improvement.

Suggest an edit

Tell us what should be corrected, clarified, or improved. Submission will be connected to Foxipa’s contribution service later.

No information is sent anywhere yet. Your suggestion is only prepared in your browser.