Python String isnumeric() Method

The isnumeric() method checks whether all characters in a string are numeric characters.

Syntax

string.isnumeric()

Parameters

No parameters.

Return Value

Returns True if all characters in a string are numeric.

Returns False if the string is empty or contains any non-numeric characters.

What Counts as Numeric Characters?

The numeric() method considers the following as numeric:

  • Digits (0-9)
  • Superscripts (¹, ²)
  • Subscripts (₁, ₂)
  • Fractions (½, ¾)
  • Characters from other number systems (like Roman numerals, Chinese/Arabic/Japanese/Devanagari numerals)

Examples

Check if a String is Numeric

print("123".isnumeric())    # True
print("\u0035".isnumeric()) # True (Unicode for 5)
print("²".isnumeric())      # True (Superscript digit)
print("₃".isnumeric())       # True (Subscript digit)
print('٢'.isnumeric())      # True (2 in Arabic)
print("1.5".isnumeric())    # False (contains decimal point)
print("123abc".isnumeric()) # False (contains letters)
print("-5".isnumeric())     # False (contains negative sign)
print("½".isnumeric())      # True (Fraction: one-half)

isnumeric() vs isdigit() method

Both isnumeric() and isdigit() are used to check if characters in a string are numeric, but they have important differences in what they consider “numeric”.

Character Typeisnumeric()isdigit()
Basic Digits (0–9)TrueTrue
Arabic Digits (e.g., ٢)TrueTrue
Devanagari Digits (e.g., १२)TrueTrue
Superscripts (², ³)TrueTrue
Subscripts (₁, ₂)TrueTrue
Fractions (½, ¾)TrueFalse
Roman Numerals (Ⅷ, Ⅻ)TrueFalse
Floating Point Numbers (1.5)FalseFalse
Negative Numbers (-5)FalseFalse
Empty String (“”)FalseFalse