Count uppercase letters in a file

EasyFile Handling Programs · 27 of 38

Write a Python program to count uppercase letters in a file.

Advertisement
Output
7

Approach

  1. sum(ch.isupper() for ch in text).

Solution

Python
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
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More file handling programs

← All 38 File Handling Programs