Python isnumeric() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

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()
CallWhat 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 ValueDescription
boolTrue 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())

How It Works

  1. Ordinary digits. Plain "123" passes all three checks.
  2. A superscript is wider. isdecimal() says False, while isdigit() and isnumeric() say True.
  3. A fraction only passes the widest check. Only isnumeric() returns True for the one half character.
  4. Other scripts count too. The Arabic-Indic digit three is a true decimal digit, so all three checks pass.

Example 2 — Do Not Trust isnumeric() Before int()

Check some typed values, then see a numeric character that int() still cannot read.

python
for text in ["42", "-5", "4.5", ""]:
    print(repr(text), text.isnumeric())

half = "\u00bd"
print(half.isnumeric())
try:
    int(half)
except ValueError:
    print("int() cannot read it")

How It Works

  1. Only digits pass. A minus sign and a decimal point are not numeric, and the empty string is False.
  2. A numeric character. The fraction one half is numeric, so isnumeric() prints True.
  3. 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))

How It Works

  1. Test each character. The comprehension walks over the text and keeps a character when isnumeric() is True.
  2. Three digits remain. The letters, spaces, and commas are dropped.
  3. 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.
False. The string needs at least one character.

Next: isprintable()

True if every character is printable, with no tabs, line breaks, or control characters.

isprintable() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful