str.isdecimal()

The strictest "is this a base-10 integer literal" check — the narrowest of the numeric-check trio.

String methodPython 1.0+Live demo
Common call
if s.isdecimal():
Returns
True or False
Replaces
the manual `all(c in "0123456789" for c in s)` — but also accepts non-ASCII decimal digits
Watch out
"3.14".isdecimal() is False (the dot!); "-42".isdecimal() is False (the minus!)
str.isdecimal()
bool

Demo

Live evaluation
Try:
Inputs
stringstrthe string to test
Output
'12345'.isdecimal()
True

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

Strict integer-literal check
Reject anything that is not a base-10 integer.
if s.isdecimal():
    value = int(s)
The three widths
isdecimal is narrowest, isdigit is middle, isnumeric is widest.
"²".isdecimal()      # False (superscript)
"²".isdigit()        # True
"²".isnumeric()      # True
"Can I safely call int() on this?"
isdecimal is a necessary but not sufficient condition — int() also accepts leading whitespace and a sign.
# safe int() if isdecimal is True (no whitespace or sign)
if s.isdecimal():
    value = int(s)   # will not raise

Examples

1. ASCII digits
"12345".isdecimal()
Returns
True
2. Arabic-Indic
"٥٦٧".isdecimal()
Returns
True
3. Devanagari
"१२३".isdecimal()
Returns
True
4. Superscript
"²".isdecimal()
Returns
False # not a decimal digit
5. Roman numeral
"Ⅳ".isdecimal()
Returns
False
6. Fraction
"½".isdecimal()
Returns
False
7. Decimal point
"3.14".isdecimal()
Returns
False # the dot
8. Negative
"-42".isdecimal()
Returns
False # the minus
9. Empty is False
"".isdecimal()
Returns
False

Pitfalls

1. isdecimal, isdigit, isnumeric — three widths of "numeric"
The three checks nest. isdecimal is narrowest (Unicode category Nd only). isdigit adds a few more (like superscripts). isnumeric is widest (Roman numerals, fractions, everything numeric).
Wrong tool for the job
"²".isdecimal()   # want True?
False — need isdigit or isnumeric
Match the tool to the input
"²".isdigit()
"½".isnumeric()
True
2. Decimal points fail this check
The decimal point itself is not a decimal DIGIT — it is punctuation. Same with the minus sign, plus sign, comma, and any other non-digit character.
Punctuation rejected
"3.14".isdecimal()
False
Parse instead
try:
    float(s)
    is_number = True
except ValueError:
    is_number = False
True on "3.14"
3. Empty string returns False
Same rule across the numeric-check trio — empty is always False. Unlike isascii and isprintable, which return True on empty.
Wrong expectation
"".isdecimal()
False
Guard first
s and s.isdecimal()
covers the empty case
4. Non-ASCII decimal digits still pass
isdecimal accepts ANY Unicode decimal digit — not just ASCII 0-9. This is usually fine for validation but might be surprising if you strictly meant "ASCII digits only".
Non-Latin passes
"٥٦٧".isdecimal()
True
ASCII-only
s.isascii() and s.isdecimal()
False on "٥٦٧"

When to use

Use it
  • 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
Reach for something else
  • 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

Complexity
O(n) — one linear scan
Return
bool — True or False
CPython impl
Objects/unicodeobject.c :: unicode_isdecimal
Memory
No allocation
Thread-safe
Yes — strings are immutable

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.

History

1.0
isdecimal() has been part of str since Python 1.0.
3.0
Full Unicode support — accepts every character in Unicode category Nd.