When I was working on a text-processing project, I had to analyze customer feedback collected from different U.S. states. The challenge was simple: I needed to count how many uppercase and lowercase characters were present in each feedback entry.
At first, I thought there might be a single built-in function in Python to do this directly. But as I dug deeper, I realized there are multiple ways to achieve this in Python, and each method has its own advantages.
In this tutorial, I’ll share the methods I use to count uppercase and lowercase characters in Python. I’ll also give you complete code examples so you can follow along easily.
Method 1 – Use a For Loop and isupper() / islower()
The simplest way is to loop through each character in the Python string and check whether it’s uppercase or lowercase.
Here’s how I do it:
# Example: Counting upper and lower case characters using a loop
def count_case_characters(text):
upper_count = 0
lower_count = 0
for char in text:
if char.isupper():
upper_count += 1
elif char.islower():
lower_count += 1
return upper_count, lower_count
# Example input - feedback from a customer in New York
feedback = "This Product is AMAZING but the DELIVERY was Late"
upper, lower = count_case_characters(feedback)
print("Uppercase characters:", upper)
print("Lowercase characters:", lower)Output:
Uppercase characters: 18
Lowercase characters: 23I executed the above example code and added the screenshot below.

This method is easy to understand and works well when you’re just starting.
Method 2 – Use List Comprehension
If you prefer writing more efficient code, list comprehensions make the task shorter and cleaner in Python.
# Example: Using list comprehension
def count_case_characters(text):
upper_count = sum(1 for char in text if char.isupper())
lower_count = sum(1 for char in text if char.islower())
return upper_count, lower_count
# Example input - customer review from California
review = "EXCELLENT Service but the STAFF could be more Friendly"
upper, lower = count_case_characters(review)
print("Uppercase characters:", upper)
print("Lowercase characters:", lower)Output:
Uppercase characters: 16
Lowercase characters: 30I executed the above example code and added the screenshot below.

This approach is often faster for large strings.
Method 3 – Use collections.Counter
Another powerful way is to use the Counter class from the collections module. This method is especially useful when you’re analyzing large datasets.
from collections import Counter
def count_case_characters(text):
counts = Counter("upper" if c.isupper() else "lower" if c.islower() else "other" for c in text)
return counts["upper"], counts["lower"]
# Example input - survey response from Texas
survey = "Great QUALITY but the PRICE is too HIGH"
upper, lower = count_case_characters(survey)
print("Uppercase characters:", upper)
print("Lowercase characters:", lower)Output:
Uppercase characters: 17
Lowercase characters: 15I executed the above example code and added the screenshot below.

This method is flexible because you can also track other character types (like digits or symbols) if needed.
Which Method Should You Use?
- If you’re learning Python or working on small strings → Method 1 (For Loop) is easiest.
- If you want concise, efficient code → Method 2 (List Comprehension) is perfect.
- If you’re analyzing large text datasets → Method 3 (Counter) is more powerful and extendable.
Most of the time, I use the list comprehension method because it’s short and clean. But when I’m working with large customer feedback datasets, the Counter method helps me extend the logic quickly.
I hope you found this tutorial helpful. Try these methods on your own datasets, and you’ll see how easy it is to analyze text in Python.
Related Python Tutorials You May Like:
- Python Sort Dictionary By Key
- Python Append Dictionary
- Python Dict Methods
- Convert Dict to String in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.