Home

strisdecimal

str.isdecimal is a string method in Python that returns True if all characters in a string are decimal digits and there is at least one character. It checks characters against the Unicode decimal digit category, ensuring that every character is a decimal digit (Nd), and that the string is non-empty.

How it works

- The method evaluates the entire string. If any character is not a decimal digit, or if the

- Decimal digits include characters like 0–9, as well as other Unicode decimal digits such as fullwidth

Examples

- "123".isdecimal() -> True

- "123".isdecimal() -> True

- "123.4".isdecimal() -> False (the period is not a decimal digit)

- "Ⅻ".isdecimal() -> False (the character is a numeric but not a decimal digit)

- "".isdecimal() -> False

- "+123".isdecimal() -> False (the plus sign is not a decimal digit)

Relation to other methods

- isdecimal is the most restrictive of the common string numeric checks. It confirms only decimal digits.

- isnumeric returns True for a broader set of numeric characters, including characters like "¼" and some numerals

- isdigit also accepts additional digit-like characters beyond the strictly decimal digits, such as superscript numbers.

Usage and limitations

- str.isdecimal is useful for validating strings that should represent non-negative decimal integers, without signs or separators.

- It will not recognize numbers written with signs, decimal points, or fractional symbols.

- For parsing numeric input, isdecimal can be used as a preliminary check before converting with int()

string
is
empty,
it
returns
False.
digits
used
by
some
Asian
scripts.
from
other
scripts.
or
similar
routines.