A statement to check whether the given character, ch is an alphabet or a number.
A statement to check whether the given character, ch is an alphabet or a number.
Required statement:
``python
print(ch.isalnum())
`
The built-in string method isalnum() returns True if the character ch is either an alphabet letter or a digit, and False` otherwise.
Marking Scheme
- 11 mark for the correct statement `print(ch.isalnum())`; the equivalent `ch.isalpha() or ch.isdigit()` is also accepted.
Hint
Look for the single string method whose name literally combines 'alphabet' and 'number' — alnum.
Quick Oral Answer
ch.isalnum() returns True if ch is a letter or a digit, giving a single built-in check for whether a character is alphanumeric.
Analysis & Explanation
This question tests knowledge of Python's built-in character-classification string methods.
Why ch.isalnum() is correct
isalnum()checks whether every character in the string is alphanumeric — meaning it is a letter (A-Z, a-z) OR a digit (0-9).- Since
chis a single character,ch.isalnum()directly answers 'is ch an alphabet or a number?' in one built-in call.
Equivalent alternative
- The same check can also be written as
ch.isalpha() or ch.isdigit(), which combines two separate built-in methods with a logical OR, giving an identical True/False result.
Common Mistakes
- 1Using only `ch.isalpha()`, which checks for alphabets alone and incorrectly returns False for a digit character.
- 2Forgetting that these string methods only work correctly on a SINGLE character string when checking one character; on multi-character strings they check that ALL characters satisfy the condition.
Interesting Facts
`isalnum()` returns False for an empty string, since there is no character to satisfy the check — this edge case is a favourite CBSE viva question.
Python's `str.isalnum()` also returns True for many Unicode numeric and alphabetic characters beyond plain ASCII, such as accented letters and superscript digits.
Spotted a mistake or something unclear?
Tell us — we fix reported answers fast.
Frequently Asked Questions
What does ch.isalnum() return for a space character?
It returns False, since a space is neither an alphabet letter nor a digit.
Can isalpha() or isdigit() be used instead of isalnum()?
Yes, `ch.isalpha() or ch.isdigit()` gives the same True/False result as `ch.isalnum()` for a single character.