Wednesday, March 18, 2026

Changing String Case in Python- Methods and Examples

If you’ve ever worked with text in Python, you’ve likely needed to adjust its case. In this tutorial, we’ll explore all the built-in methods for changing string case in Python- from converting text to lowercase or uppercase, to formatting titles and capitalizing words.

Python provides several powerful and easy-to-use string methods for case conversion and case checking. Here’s a quick summary of the most commonly used ones:

  1. str.lower()- Returns a copy of the string with all characters converted to lowercase.
  2. str.upper()- Returns a copy of the string with all characters converted to uppercase.
  3. str.capitalize()- Returns a copy of the string with the first character capitalized and the rest lowercased.
  4. str.title()- Returns a titlecased version of the string, where each word starts with an uppercase character and the remaining characters are lowercase.

Along with methods for changing string case in Python, the language also provides handy built-in functions to check the case of a string. These methods are useful when you want to verify whether case conversion is needed before performing operations like formatting or normalization.

Here are the most commonly used case-checking methods:

  1. str.islower()- Returns True if all cased characters in the string are lowercase and there is at least one cased character; otherwise returns False.
  2. str.isupper()- Returns True if all cased characters in the string are uppercase and there is at least one cased character; otherwise returns False.
  3. str.istitle()- Returns True if the string is in title case (each word starts with an uppercase letter followed by lowercase letters) and contains at least one character.

Changing String case in Python examples

1. Changing String to all lower case or to all upper case.

s = "This is a TEST String"
print('String in all lower case-',s.lower())
s = "This is a Test String"
print('String in all upper case-', s.upper())

Output

String in all lower case- this is a test string
String in all upper case- THIS IS A TEST STRING

2. Capitalizing the String. First character will be capitalized, if there is any other upper case character in the String that is lower cased.

s = "this is a TEST String"
print('String Capitalized-',s.capitalize())

Output

String Capitalized- This is a test string

3. String title cased. Using title() method you can title cased a String. This method capitalizes the first character of every word.

s = "this is a TEST String"
print('String Title cased-',s.title())

Output

String Title cased- This Is A Test String

4. Checking the case before changing. You can also check the case before changing the case of the String and change the case only if needed. This is an optimization because any String modification method results in a creation of a new String as String is immutable in Python.

s = "this is a test string"
#change only if not already in lower case
if not s.islower():
    s = s.lower()
else:
    print('String already in lower case')
print(s)

Output

String already in lower case
this is a test string
s = "This is a test String"
#change only if not already in upper case
if not s.isupper():
    s = s.upper()
else:
    print('String already in upper case')
print(s)

Output

THIS IS A TEST STRING

That's all for this topic Changing String Case in Python- Methods and Examples. If you have any doubt or any suggestions to make please drop a comment. Thanks!

>>>Return to Python Tutorial Page


Related Topics

  1. Getting Substring in Python String
  2. String Slicing in Python
  3. String Length in Python - len() Function
  4. Convert String to float in Python
  5. Python Program to Check Armstrong Number

You may also like-

  1. Python continue Statement With Examples
  2. Encapsulation in Python
  3. Class And Object in Python
  4. List in Python With Examples
  5. Just In Time Compiler (JIT) in Java
  6. Bucket Sort Program in Java
  7. Spring MVC Exception Handling Tutorial
  8. What is Hadoop Distributed File System (HDFS)