Python’s str.isdigit() returns True only when a string is nonempty and every character has Unicode numeric type Digit or Decimal. That includes ordinary decimal digits and characters such as superscript two (²), but not every symbol that represents a number: vulgar fraction one fifth (½) fails. The right method depends on the input format you intend to accept.
What does str.isdigit() accept?
isdigit() tests the entire string, not whether it contains a digit somewhere. The string must have at least one character, and every character must qualify under Python’s Unicode definition. Python defines a digit here as a character whose Unicode Numeric_Type is Digit or Decimal. Python’s built-in types documentation gives ordinary digits, Arabic-Indic digits, and superscript two as examples that pass.
As an Amazon Associate I earn from qualifying purchases.
'123'.isdigit() # True
'٠١٢'.isdigit() # True: Arabic-Indic decimal digits
'²'.isdigit() # True: superscript two
''.isdigit() # False: the string is empty
'12a'.isdigit() # False: not every character is a digit
Because it checks every character, a sign, space, decimal separator, or punctuation mark makes the result false. For example, strings such as '-12', '12.5', and ' 12' do not consist entirely of qualifying digits.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallWhy does '½'.isdigit() return False?
A character can have a numeric value without being classified as a digit by Unicode. The fraction character ½ has a numeric value, but its numeric type is not Digit or Decimal, so isdigit() rejects it. Python documents the contrast directly: '½'.isdigit() is False, while '²'.isdigit() is True. The Unicode Standard distinguishes decimal digits, compatibility digits such as superscripts, and other numeric characters.
#1 Best Overall
How do isdecimal(), isdigit(), and isnumeric() differ?
All three methods require a nonempty string whose every character meets that method’s Unicode criterion. Their accepted character sets differ:
| Method | Unicode criterion | What the distinction means |
|---|---|---|
isdecimal() |
General Category Nd / Numeric_Type=Decimal |
Limited to decimal digits used to form decimal-radix numbers; Arabic-Indic digits are one example. |
isdigit() |
Numeric_Type=Digit or Numeric_Type=Decimal |
Includes the decimal digits accepted by isdecimal(), plus special digit characters such as superscripts. |
isnumeric() |
Numeric_Type=Digit, Decimal, or Numeric |
The broadest test; it also accepts characters with numeric values, including vulgar fractions. |
For the superscript two character, the results are isdecimal() == False, isdigit() == True, and isnumeric() == True. For vulgar fraction one fifth (⅕), isnumeric() is true while isdigit() is false. Python’s documentation includes these examples.
Rank #2
Which method should you use to validate input?
Choose the check that matches the characters your application’s input grammar permits. The method name alone does not define what your application should accept.
- Use
isdecimal()when you want Unicode decimal digits only. - Use
isdigit()when special digit characters, including superscripts, should count. - Use
isnumeric()when characters with Unicode numeric values, including fractions, should count. - Use an explicit ASCII rule when only the characters
0through9are allowed. These methods are Unicode-aware, not ASCII-only.
A passing result is only a character-property check. It does not establish that a string is a valid Python integer literal, a decimal number in your application’s format, or an ASCII digit sequence. For ASCII digits, one straightforward check is:
value.isascii() and value.isdigit()
The isascii() condition rules out non-ASCII characters; isdigit() then verifies that the nonempty string consists entirely of digits. If the required format allows an empty value, signs, separators, or other syntax, define and validate those rules separately rather than treating this expression as a general number parser.
How can you inspect a character’s Unicode properties?
Python’s unicodedata module exposes separate functions for decimal, digit, and numeric values, as well as a general category lookup. These help explain why a particular character passes one predicate and fails another. The module uses the Unicode Character Database shipped with the Python runtime, so behavior for newly added or reclassified characters can depend on that database version. Check unicodedata.unidata_version when behavior must be tied to a specific Unicode release. The unicodedata documentation describes these APIs and the database version attribute.
Quick Recap
Best Value
import unicodedata
char = '²'
print(unicodedata.category(char))
print(unicodedata.decimal(char, None))
print(unicodedata.digit(char, None))
print(unicodedata.numeric(char, None))
print(unicodedata.unidata_version)
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.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.




