Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

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.

BeginnerPhase 5 - Category 2: Character OperationsExample 5 of 10
count-lowercase-characters.py
1# Take string input
2s = input("Enter a string: ")
3
4# Count lowercase
5count = 0
6for char in s:
7 if char.islower():
8 count += 1
9
10print(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. 1

    Initialize the lowercase counter.

  2. 2

    Test char.islower for every character.

  3. 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.