Count Lowercase Characters
Count lowercase characters in a string. Students use islower on individual characters and keep lowercase frequency separate from converting the whole response.
1# Take string input2s = input("Enter a string: ")34# Count lowercase5count = 06for char in s:7 if char.islower():8 count += 1910print(f"Lowercase characters: {count}")
Output
Enter a string: Hello World Lowercase characters: 8
In this one
- Test lowercase characters
- Keep mixed-case inputs
- Count Unicode-aware matches
How it works
- 1
Initialize the lowercase counter.
- 2
Test char.islower for every character.
- 3
Print the accumulated matches.
Edge cases
Does lowercase conversion occur?
Does lowercase conversion occur?
No. islower only tests.
What happens for empty input?
What happens for empty input?
The counter stays zero.
What's going on
The loop tests char.islower() for each code point. A match adds one, but the original character remains unchanged.
For Abc2, b and c contribute, giving two. Uppercase letters, spaces, and digits do not contribute. This method recognizes Unicode lowercase characters too, so limiting the intended domain to English would require a different explicit restriction.
Does lowercase conversion occur? No. islower only tests.
What happens for empty input? The counter stays zero.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which characters count in Abc2?
Pick an answer to check it.
Question 2
Does lowercase conversion occur?
Pick an answer to check it.
Questions people ask
Does lowercase conversion occur?
No. islower only tests.
What happens for empty input?
The counter stays zero.
Which characters count in Abc2?
b and c.
๐Related Content
- ๐
Phase 5 - Learn Concepts
Review Phase 5 concepts and explanations
- ๐
Phase 5 - Quiz
Test your Phase 5 understanding with quiz questions
- ๐ป
Phase 5 - All Practice Problems
Explore all practice problems for Phase 5
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum