Free tools Windows power users keep installed
One-click scans. No signup required.
iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Python’s str.isdigit() returns True only when a string is nonempty and every character in it is a Unicode digit of type Digit or Decimal. It accepts ordinary decimal digits and some special digit characters such as superscript two, but not every character with a numeric value: '½'.isdigit() is False.
What isdigit() accepts
The method tests the Unicode properties of every character in the string. Python’s definition includes characters whose Unicode Numeric_Type is Digit or Decimal. Decimal digits such as the familiar 0–9 qualify, as do decimal digits in other scripts and compatibility digits such as superscripts. See the Python built-in types documentation for the formal definition and examples.
'123'.isdigit() # True
'٠١٢'.isdigit() # True: Arabic-Indic decimal digits
'²'.isdigit() # True: superscript two
These are Unicode-aware checks, not ASCII-only checks. Arabic-Indic numerals and superscripts can pass even though they are not ASCII characters from 0 through 9.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →What isdigit() rejects
isdigit() does not mean “has a numeric value.” A vulgar fraction such as one fifth is numeric, but it is not of Unicode numeric type Digit or Decimal, so it fails. The empty string also fails, and every character must qualify: a letter, sign, space, decimal separator, or punctuation mark makes the whole result false.
#1 Best Overall
'½'.isdigit() # False: numeric value, but not Digit or Decimal
''.isdigit() # False: the string must be nonempty
'12a'.isdigit() # False: not every character qualifies
'-12'.isdigit() # False: the minus sign is not a digit
'1.2'.isdigit() # False: the decimal point is not a digit
Python documents the Unicode character distinctions and examples in its built-in types reference. The distinctions among decimal digits, compatibility digits, and other numeric characters are also described in Unicode 18.0.0, Chapter 4.
Choosing among isdecimal(), isdigit(), and isnumeric()
All three methods require a nonempty string and test every character, but they accept different sets of Unicode characters. Choose based on the input format your program intends to allow.
Rank #2
| Method | Unicode character types accepted | Practical use | Example |
|---|---|---|---|
isdecimal() |
Numeric_Type=Decimal (General Category Nd) |
Accept Unicode decimal digits used to form decimal-radix numbers. | '²'.isdecimal() is False; Arabic-Indic decimal digits pass. |
isdigit() |
Numeric_Type=Digit or Decimal |
Accept decimal digits plus special digit characters, including superscripts. | '²'.isdigit() is True. |
isnumeric() |
Numeric_Type=Digit, Decimal, or Numeric |
Accept the broadest set, including characters with numeric values such as vulgar fractions. | '⅕'.isnumeric() is True; '⅕'.isdigit() is False. |
The Python reference gives the distinctions and examples, including '²' returning (False, True, True) for isdecimal(), isdigit(), and isnumeric(). It also documents the one-fifth example. See the method definitions.
Recommended Free Tools
Use an ASCII rule when the input must be ASCII
If a protocol, identifier, or field permits only ASCII characters 0 through 9, do not use isdigit() as the validator: its Unicode scope is broader. One direct check is:
def is_ascii_digits(value: str) -> bool:
return bool(value) and all('0' <= char <= '9' for char in value)
For the same rule in a regular expression, use an explicit ASCII range and anchor it to the entire string, for example re.fullmatch(r'[0-9]+', value). The explicit range avoids treating non-ASCII digits as acceptable.
A passing result is not number or integer validation
isdigit() reports a character-property test; it does not establish that text matches a Python integer literal, a decimal number format, or your application’s input grammar. For instance, a string containing superscript two passes the test, but that alone does not make it an appropriate integer representation for your field. Define the accepted syntax first, then validate or parse according to that syntax.
Inspecting a character’s Unicode properties
When a character’s behavior is surprising, Python’s unicodedata module provides separate functions for its decimal, digit, and numeric values, along with its general category. These distinguish the properties behind the three string methods.
import unicodedata
for char in '²½٠':
print(
repr(char),
unicodedata.category(char),
unicodedata.decimal(char, None),
unicodedata.digit(char, None),
unicodedata.numeric(char, None),
)
The available Unicode database depends on the Python runtime. To see the database version used by the installed runtime, inspect unicodedata.unidata_version. Python documents these APIs in the unicodedata reference; consult the documentation matching your deployed Python version when exact Unicode-version behavior matters.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

