str.isdecimal()

str.isdecimal()
Returns: bool · Added in v3.x · Updated March 13, 2026 · String Methods
stdlib string validation

The .isdecimal() method checks whether all characters in a string are decimal characters and the string contains at least one character. Decimal characters are those that can be used to form numbers in base 10—the digits 0 through 9 in various Unicode scripts.

This method is useful when you need to validate that user input contains only numeric characters that can be used in mathematical operations. Unlike .isdigit(), which accepts superscripts and other numeric Unicode characters, .isdecimal() is stricter—it only accepts characters that are actual decimal digits.

Syntax

str.isdecimal()

Parameters

This method takes no parameters.

Examples

Basic usage

text = "12345"
print(text.isdecimal())
# True

with_letters = "123abc"
print(with_letters.isdecimal())
# False (contains letters)

with_space = "123 45"
print(with_space.isdecimal())
# False (space is not a decimal)

Unicode decimal characters

Python 3 supports decimal characters from many Unicode scripts beyond ASCII:

# Standard ASCII digits
print("123".isdecimal())
# True

# Arabic-Indic digits (U+0660 through U+0669)
arabic = "\u0660\u0661\u0662"
print(arabic.isdecimal())
# True

# Devanagari digits (U+0966 through U+096F)
devanagari = "\u0966\u0967\u0968"
print(devanagari.isdecimal())
# True

# Fullwidth digits (U+FF10 through U+FF19)
fullwidth = "\uff10\uff11\uff12"
print(fullwidth.isdecimal())
# True

Superscripts are not decimal

Superscript numbers look like digits but aren’t classified as decimal characters:

# Superscript digits (U+2070, U+00B9, U+00B2, U+00B3)
superscript = "\u00B2"
print(superscript.isdigit())
# True
print(superscript.isdecimal())
# False (superscripts are not decimal characters)

# This matters when parsing user input that might look numeric
# but isn't usable in arithmetic

Common Patterns

Validating numeric input

def is_numeric_input(s):
    """Check if string represents a valid integer."""
    if not s:
        return False
    return s.isdecimal()

print(is_numeric_input("42"))
# True
print(is_numeric_input("3.14"))
# False (decimal point not allowed)
print(is_numeric_input("-5"))
# False (minus sign not allowed)
print(is_numeric_input(""))
# False

Processing form data

def validate_postal_code(code):
    """Validate US ZIP code format."""
    # ZIP codes must be exactly 5 or 9 decimal digits
    if len(code) == 5 and code.isdecimal():
        return True
    if len(code) == 9 and code.isdecimal():
        return True
    return False

print(validate_postal_code("90210"))
# True
print(validate_postal_code("90210-1234"))
# False (hyphen not allowed)
print(validate_postal_code("ABCDE"))
# False

Differences Between isdigit, isnumeric, and isdecimal

These three methods seem similar but have important differences:

s = "123"

print(s.isdigit())
# True
print(s.isdecimal())
# True
print(s.isnumeric())
# True

# Superscript 2
s = "\u00B2"  # ²

print(s.isdigit())
# True
print(s.isdecimal())
# False (not a decimal character)
print(s.isnumeric())
# True

# Roman numeral
s = "\u2165"  # Ⅴ

print(s.isdigit())
# False
print(s.isdecimal())
# False
print(s.isnumeric())
# True

# Arabic-Indic digit
s = "\u0660"  # ٠

print(s.isdigit())
# True
print(s.isdecimal())
# True
print(s.isnumeric())
# True

The distinction matters when you’re working with international numeric input or parsing data that might contain Unicode number representations.

Behavior Notes

  • Returns False for empty strings—the string must contain at least one character
  • Only returns True for characters in Unicode decimal digit category (Nd)
  • Does not accept minus signs, decimal points, or other numeric symbols
  • Use this method when you need to ensure strings can be converted to integers with int()

See Also