isnumeric() returns True if the string is not empty and every character has a numeric meaning. That includes the ordinary digits 0 to 9, superscripts such as \u00b2, fractions such as \u00bd, and digit characters from other writing systems.
It is the widest of the three number checks. A minus sign, a decimal point, a comma, or a space is not numeric, so "-5" and "3.14" return False. An empty string returns False too.
text.isnumeric() is a method of the built-in str type: call it on a string with dot notation. No import is needed, and it never changes the original string.
Syntax
Call it on any string. There are no arguments, but the parentheses are required.
python
ok = text.isnumeric()
Call
What it does
"12345".isnumeric()
Returns True. Every character is a digit.
"\u00bd".isnumeric()
Returns True. The vulgar fraction one half is a numeric character.
"3.14".isnumeric()
Returns False. The decimal point is not a numeric character.
Compare it with isdigit(), which also accepts superscripts, and isdecimal(), which accepts only true decimal digits and is the safest check before int().
Library declarations
python
str.isnumeric() -> bool
# returns: True if the string is not empty and every character is numeric
# an empty string returns False
Parameters
This method takes no arguments. It always checks the whole string.
Return Value
Return Value
Description
bool
True if the string is not empty and every character is numeric, otherwise False.
Python Examples
Example 1 — isdecimal(), isdigit(), and isnumeric() Side by Side
Run all three checks on four kinds of numeric text.
python
samples = {
"ascii digits": "123",
"superscript": "\u00b2",
"fraction": "\u00bd",
"arabic digit": "\u0663",
}
for label, s in samples.items():
print(label, s.isdecimal(), s.isdigit(), s.isnumeric())
Only digits pass. A minus sign and a decimal point are not numeric, and the empty string is False.
A numeric character. The fraction one half is numeric, so isnumeric() prints True.
But int() fails.int() does not understand a fraction character and raises ValueError, which the except block catches.
Example 3 — Collect the Numeric Characters
Filter the characters of a sentence and join the digits.
python
text = "Room 7, floor 3, 2 beds"
digits = [ch for ch in text if ch.isnumeric()]
print(digits)
print("".join(digits))
Output
['7', '3', '2']
732
How It Works
Test each character. The comprehension walks over the text and keeps a character when isnumeric() is True.
Three digits remain. The letters, spaces, and commas are dropped.
Join them."".join(digits) glues the pieces into the text "732".
Frequently Asked Questions
It returns True if the string is not empty and every character is numeric, such as a digit, a superscript, a fraction, or a number character from another script.
isdecimal() is the strictest and accepts only decimal digits. isdigit() also accepts superscripts. isnumeric() is the widest and also accepts fractions and similar characters.
No. The minus sign and the decimal point are not numeric characters, so "-5" and "3.14" return False.
Not safely. Some numeric characters, such as a fraction, make int() raise ValueError. Use isdecimal() for plain digits or try/except for everything else.