Python Practice › File Handling Programs › Program 34
Count vowels in a file
Write a Python program to count the vowels in a file.
Output
8
Approach
- Count characters in “aeiou” after lower-casing.
Solution
with open("story.txt", "w") as f: f.write("Python file handling is easy\n") with open("story.txt") as f: print(sum(ch in "aeiou" for ch in f.read().lower()))Output
8
Learn the concept
New to this topic? Read the lesson, then come back.