Python isdecimal() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
String

Definition

In Python, isdecimal() returns True when every character is a decimal digit and the string is not empty.

It takes no arguments. Signs, dots, letters, and spaces make it return False. It is stricter than isdigit().

Syntax

Call isdecimal on the string. Start with this line.

python
ok = text.isdecimal()
CallWhat it does
"42".isdecimal()Returns True.
"3.14".isdecimal()Returns False (dot is not a digit).

isdecimal() checks characters. It does not parse floats or signed numbers.

Library declarations
python
str.isdecimal() → bool

Parameters

This method has no parameters.

Return Value

Return ValueDescription
boolTrue if all characters are decimal digits.

Python Examples

Example 1 — Basic isdecimal() Checks

See what passes and what fails—including the empty string.

python
print("123".isdecimal())
print("12.3".isdecimal())
print("-5".isdecimal())
print("".isdecimal())

How It Works

  1. All digits. "123" has only 0–9 → True.
  2. Dot fails. "." is not a decimal digit → False.
  3. Sign fails. "-" is not a decimal digit → False.
  4. Empty fails. "" is never decimal → False.

Example 2 — Validate Clean Input

Strip spaces, then accept only pure digit strings before converting.

python
raw = "  42  "
text = raw.strip()

if text.isdecimal():
    number = int(text)
    print("OK:", number)
else:
    print("Not a whole number")

How It Works

  1. Clean first. strip() removes leading/trailing spaces.
  2. Gate with isdecimal. Only digit-only text continues.
  3. Safe convert. int(text) is safe after a True check for ASCII digits.
  4. Reject junk. Signs, dots, or letters would take the else branch.

Example 3 — isdecimal() vs isdigit()

Superscript digits pass isdigit() but fail isdecimal().

python
s = "²"  # superscript two

print("isdecimal:", s.isdecimal())
print("isdigit:  ", s.isdigit())

How It Works

  1. Same character. Both methods inspect "²".
  2. isdecimal(). Superscripts are not decimal digits → False.
  3. isdigit(). Accepts some extra digit forms → True.
  4. Pick by goal. Strict base-10 digits → isdecimal; broader digit check → isdigit.

Frequently Asked Questions

It returns True if every character is a decimal digit and the string is not empty.
No. "3.14" and "-5" both return False.
isdecimal() is stricter. isdigit() can accept some characters such as superscripts.
It returns False.
No. It only returns a boolean.

Next: isdigit()

Learn the broader digit check and how it differs from isdecimal().

isdigit() →

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.

9 people found this page helpful