Python
string methods
isdigit
isnumeric
isdecimal

What's the difference between str.isdigit, isnumeric and isdecimal in Python?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

str.isdecimal(), str.isdigit(), and str.isnumeric() all check whether every character in a string belongs to a numeric category, but they do not mean the same thing. The difference comes from Unicode character classes. In practice, isdecimal is the strictest, isnumeric is the broadest, and isdigit sits in the middle.

isdecimal() Is the Strictest

isdecimal() returns True only for characters that are decimal digits in Unicode. This is the closest match to ordinary base-10 digits used in standard number strings.

python
1samples = ["123", "١٢٣", "²", "Ⅳ"]
2
3for value in samples:
4    print(value, value.isdecimal())

Typical results:

  • '"123" is decimal.'
  • Arabic-Indic digits such as "١٢٣" are also decimal.
  • Superscript digits such as "²" are not decimal.
  • Roman numerals such as "Ⅳ" are not decimal.

If your goal is "can this string be treated like a plain integer string," isdecimal() is often the safest starting point.

isdigit() Accepts More Digit-Like Characters

isdigit() includes decimal digits, but it also accepts some characters that are considered digits without being normal decimal characters, such as superscript digits.

python
1samples = ["123", "²", "١٢٣", "Ⅳ"]
2
3for value in samples:
4    print(value, value.isdigit())

This means:

  • '"123" returns True.'
  • '"²" also returns True.'
  • '"Ⅳ" still returns False.'

That makes isdigit() slightly broader than isdecimal(). It is useful when digit-like Unicode characters should count, but it can surprise you if you expected only standard decimal input.

isnumeric() Is the Broadest

isnumeric() covers everything from isdigit() plus additional Unicode numeric characters such as vulgar fractions and some numeral symbols.

python
1samples = ["123", "²", "Ⅳ", "½"]
2
3for value in samples:
4    print(value, value.isnumeric())

Here:

  • '"123" is numeric.'
  • '"²" is numeric.'
  • '"Ⅳ" is numeric.'
  • '"½" is numeric.'

This method answers a Unicode question, not a parsing question. A string can be "numeric" according to Unicode and still not be acceptable to int() or float() in the form you expect.

Compare the Three Directly

The easiest way to remember the relationship is:

python
1tests = ["123", "²", "Ⅳ", "½"]
2
3for text in tests:
4    print(
5        text,
6        "decimal=", text.isdecimal(),
7        "digit=", text.isdigit(),
8        "numeric=", text.isnumeric(),
9    )

Conceptually:

  • Every decimal string is also a digit string and a numeric string.
  • Some digit strings are not decimal strings.
  • Some numeric strings are neither decimal nor digit strings.

So the inclusion order is:

  • 'isdecimal inside isdigit'
  • 'isdigit inside isnumeric'

Choose Based on What You Need to Accept

These methods are often used as if they were input validators for parsing numbers, but that is only partly true. The right choice depends on the business rule:

  • Use isdecimal() for ordinary integer-like user input.
  • Use isdigit() if superscript or similar digit characters should count.
  • Use isnumeric() only when broad Unicode numeric recognition is actually desired.

If you want to validate Python number syntax such as negative numbers, decimal points, or scientific notation, none of these methods is enough because "-12" and "3.14" all return False. In that case, actual parsing with int(), float(), or decimal.Decimal is a better strategy.

Common Pitfalls

  • Assuming all three methods are synonyms.
  • Using isnumeric() when only ordinary decimal digits should be accepted.
  • Expecting these methods to validate signed numbers or decimal points.
  • Assuming a True result guarantees int() or float() will behave the way you want.
  • Forgetting that Unicode digit categories are broader than ASCII digits.

Summary

  • 'isdecimal() is the strictest and matches standard decimal digit characters.'
  • 'isdigit() includes decimal digits plus some digit-like Unicode characters such as superscripts.'
  • 'isnumeric() is the broadest and includes fractions and numeral symbols.'
  • These methods answer Unicode character questions, not full numeric parsing questions.
  • For actual numeric input validation, parsing is often safer than character-category checks.

Course illustration
Course illustration

All Rights Reserved.