Skip to content
Tutorials Center
My learning

Topics

Python Reference Β· String Methods

Python str.isnumeric() method

Reference for Python str.isnumeric(): check for numeric characters including fractions, Roman numerals and CJK numbers, and learn why it does not mean int() works.

The isnumeric() method returns True if the string is not empty and every character has a Unicode numeric value. That is the widest of the three digit tests: it accepts ordinary digits, superscripts, fractions such as Β½, Roman numeral characters such as β…£, and numbers written in other scripts such as δΊ”.

Having a numeric value does not make a string parseable. Use it to classify characters, not to promise that int() or float() will succeed.

Python
print("12345".isnumeric())   # True
print("Β½".isnumeric())       # True

Try it

Python Comparing the three tests

Press Run (or Ctrl + Enter) to see the result here.

Program input Β· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Numeric characters and their values

Press Run (or Ctrl + Enter) to see the result here.

Program input Β· what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Syntax

Python
str.isnumeric()

This method takes no parameters.

Return value: True if the string has at least one character and all characters have the Unicode property Numeric_Type of Decimal, Digit or Numeric; otherwise False.

Raises: nothing.

Usage notes

  • Superset of the others. Every string that passes isdecimal() passes isdigit(), and every string that passes isdigit() passes isnumeric(). The reverse is not true.
  • No signs or points. "-1" and "3.5" are False because - and . have no numeric value. To validate numbers, call float() or int() in a try/except ValueError block.
  • Not an int() test. "Β½".isnumeric() is True, but int("Β½") raises ValueError.
  • Empty string is False.
  • Looking up the value. unicodedata.numeric(char) returns the numeric value of a single character as a float, for example 0.5 for "Β½".
  • Scripts. Characters like δΊ” or β…« count, which can be a surprise in forms that expect Western digits. Add isascii() when you need 0-9 only.
  • Bytes have no isnumeric(); use bytes.isdigit().