Python Practice › File Handling Programs › Program 27
Count uppercase letters in a file
Write a Python program to count uppercase letters in a file.
Output
7
Approach
sum(ch.isupper() for ch in text).
Solution
with open("story.txt", "w") as f: f.write("Learn Python At SQA Tools\n") with open("story.txt") as f: print(sum(ch.isupper() for ch in f.read()))Output
7
Learn the concept
New to this topic? Read the lesson, then come back.