str.isalnum() Alphanumeric only
Last updated: 2026-09-22
str.isalnum() Alphanumeric only
str.isalnum() returns True if the string is non-empty and every char is alphanumeric.
| Category | String Methods |
|---|---|
| Kind | Built-in Type Method |
| Python Version | all |
📝 Syntax
str.isalnum()
Returns:bool. True if the string is non-empty and every char is alphanumeric.
Mutates the original:No (returns a new object)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
True
False
False
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat does isalnum() return for an empty string?
AFalse. isalnum() requires a non-empty string, so ''.isalnum() is False.
QAre spaces and underscores alphanumeric?
ANo. 'a b'.isalnum() and 'a_b'.isalnum() are both False.
QDo Chinese characters count as alphanumeric?
AYes. Chinese characters belong to the Unicode letter category, so '中文123'.isalnum() is True. Keep this in mind when validating usernames with isalnum().
QHow do I check whether a string contains only ASCII letters and digits?
ACombine s.isalnum() and s.isascii() to exclude non-ASCII characters such as Chinese.