Check Character Type
Identify uppercase text, lowercase text, digits, or special input with Python. Students learn the order and limits of isupper, islower, and isdigit checks.
1# Take a character as input2ch = input("Enter a character: ")34# Check character type5if ch.isupper():6 print("Uppercase")7elif ch.islower():8 print("Lowercase")9elif ch.isdigit():10 print("Digit")11else:12 print("Special character")
Output
Enter a character: A Uppercase Enter a character: a Lowercase Enter a character: 5 Digit Enter a character: @ Special character
In this one
- Use character classification methods
- Understand whole-string tests
- Keep branch priority
How it works
- 1
Read the response without changing case.
- 2
Try isupper, islower, then isdigit.
- 3
Print the first matching label or the fallback.
Edge cases
What does an empty response produce?
What does an empty response produce?
All three tests are false, so the final label is Special character.
Is A1 uppercase here?
Is A1 uppercase here?
Yes. Its cased letters are uppercase; the digit does not make isupper false.
What's going on
This classifier calls string methods rather than comparing numeric character codes. The first successful test decides the label, beginning with isupper and then islower.
Input A reaches Uppercase, 5 reaches Digit, and @ reaches Special character. These methods inspect the whole response, not just its first character. For example, ABC is uppercase too, so the prompt alone does not enforce one-character input.
What does an empty response produce? All three tests are false, so the final label is Special character.
Is A1 uppercase here? Yes. Its cased letters are uppercase; the digit does not make isupper false.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which method checks digit characters?
Pick an answer to check it.
Question 2
What does an empty response produce?
Pick an answer to check it.
Questions people ask
What does an empty response produce?
All three tests are false, so the final label is Special character.
Is A1 uppercase here?
Yes. Its cased letters are uppercase; the digit does not make isupper false.
Which method checks digit characters?
isdigit.
๐Related Content
- ๐
Phase 1 - Learn Concepts
Review Phase 1 concepts and explanations
- ๐
Phase 1 - Quiz
Test your Phase 1 understanding with quiz questions
- ๐ป
Phase 1 - All Practice Problems
Explore all practice problems for Phase 1
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum