October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Python `isdigit()`: What It Accepts and What It Rejects

Python’s isdigit() checks that a nonempty string contains only Unicode decimal or digit characters. Learn why superscripts pass, fractions fail, and how to choose a validation rule.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why 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.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • 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 0 through 9 are 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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.