str.isdecimal()
The strictest "is this a base-10 integer literal" check — the narrowest of the numeric-check trio.
Demo
isdecimal() is the STRICTEST of the numeric-check trio. It accepts ONLY characters Unicode categorizes as decimal digits (category Nd) — that includes ASCII 0-9 AND non-Latin decimal digit systems (Arabic-Indic ٥٦٧, Devanagari १२३). Everything else fails: superscripts, Roman numerals, fractions, decimal points, signs, whitespace, letters. Same rule as isdigit and isnumeric for the empty case: returns False.
Common patterns
if s.isdecimal(): value = int(s)
"²".isdecimal() # False (superscript) "²".isdigit() # True "²".isnumeric() # True
# safe int() if isdecimal is True (no whitespace or sign) if s.isdecimal(): value = int(s) # will not raise
Examples
Pitfalls
"²".isdecimal() # want True?
"²".isdigit() "½".isnumeric()
"3.14".isdecimal()
try: float(s) is_number = True except ValueError: is_number = False
"".isdecimal()
s and s.isdecimal()
"٥٦٧".isdecimal()
s.isascii() and s.isdecimal()
When to use
- Strict base-10 integer literal validation
- When you want to call int() safely without a try/except
- Filtering tokens to just decimal-digit sequences
- "Is this a simple number?" questions where signs and decimals are separate
- Signed or decimal-pointed numbers → use float() with try/except
- Superscripts must pass → isdigit
- Roman numerals / fractions must pass → isnumeric
- ASCII-only digits → combine with isascii
Notes
FAQ
Three widths of numeric character. isdecimal is narrowest — only Unicode category Nd (decimal digits). isdigit adds superscripts and a few compatibility characters. isnumeric is widest — fractions, Roman numerals, every Unicode-classified numeric character.