The isdecimal() method returns True when every character in a string is a decimal digit and the string is not empty. It is ideal for validating whole-number input like PIN codes, ages, and quantities before you convert strings to integers with int().
01
Decimal Digits
0–9 and Unicode Nd.
02
Returns bool
True or False result.
03
No Arguments
Call directly on str.
04
Empty = False
Zero-length fails check.
05
Input Validation
PINs and numeric fields.
06
vs isdigit()
Stricter digit rules.
Fundamentals
Definition and Usage
In Python, isdecimal() inspects each character in a string. If every character is a decimal digit (characters in Unicode category Nd that can form base-10 numbers) and the string has at least one character, it returns True. Otherwise it returns False. For example, "12345".isdecimal() is True, but "Hello123".isdecimal() is False because of the letters.
💡
Beginner Tip
isdecimal() checks characters, not whether the whole string is a valid number. "3.14".isdecimal() is False because the dot is not a digit. Use isdecimal() for whole-number strings only.
Foundation
📝 Syntax
The isdecimal() method takes no parameters:
python
string.isdecimal()
Syntax Rules
string — any valid Python str object.
Return value — True if all characters are decimal digits and the string is non-empty; otherwise False.
No arguments — passing arguments raises TypeError.
Read-only — the original string is never modified.
Unicode — includes decimal digits from other scripts (like Arabic-Indic ٠١٢), not just ASCII 0–9.
Reference
↩ Return Value
isdecimal() always returns a boolean. It returns True only when the string contains one or more characters and every character is a decimal digit. It returns False for empty strings, strings with letters, and strings with punctuation such as ., -, or spaces.
Circled digit ① (\u2460) passes isdigit() but not isdecimal().
For strict base-10 whole numbers, prefer isdecimal().
Applications
🚀 Common Use Cases
PIN and OTP validation — ensure codes contain digits only before processing.
Form fields — verify age, quantity, or ID fields are whole numbers.
Pre-conversion checks — call isdecimal() before int(text) to avoid ValueError.
Data cleaning — flag non-numeric values in imported CSV columns.
Menu choices — validate that user input is a numeric option index.
🧠 How isdecimal() Works
1
Python reads the string
You call isdecimal() on a str object—literal or variable.
Input
2
Each character is checked
Python tests whether every character is a Unicode decimal digit (Nd). Empty strings fail immediately.
Scan
3
Boolean result is returned
True if all pass; False if any character fails or the string is empty.
Result
=
✅
Validation complete
Use the boolean to accept input or show an error message.
Important
📝 Notes
Decimal points, minus signs, plus signs, and spaces all cause False.
An empty string "" always returns False—there must be at least one digit.
Unicode decimal digits from other scripts (like Arabic-Indic) are accepted, not just ASCII 0–9.
Superscript and other compatibility digits pass isdigit() but often fail isdecimal().
isdecimal() does not check length—combine it with len() for fixed-width codes.
Wrap Up
Conclusion
The isdecimal() method is a precise way to verify that a string contains only decimal digits. It returns a clear boolean result, which makes it ideal for validating whole-number input before parsing or storing data.
Remember that it checks individual characters, not full numeric expressions. For floats or negative numbers, you need different validation—or use isdigit() when a broader digit check is enough.
Use isdecimal() for whole-number string validation
Combine with len() for PINs and fixed-length codes
Call isdecimal() before int() on user input
Prefer isdecimal() over isdigit() for strict base-10 checks
Give clear error messages when validation fails
❌ Don’t
Expect "3.14" or "-5" to pass isdecimal()
Assume an empty string returns True
Pass arguments to isdecimal()
Use it alone for float validation
Confuse isdecimal() with isdigit() without testing edge cases
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about isdecimal()
Use these points when validating numeric strings in Python.
5
Core concepts
🔢01
Decimal Digits
Base-10 characters.
Purpose
✅02
True / False
Boolean return only.
Return
🛠03
Zero Arguments
s.isdecimal()
Syntax
🔐04
PIN Checks
Whole numbers only.
Use case
⚠05
vs isdigit()
Stricter digit rules.
Compare
❓ Frequently Asked Questions
isdecimal() returns True if every character in the string is a decimal digit and the string is not empty. It returns False if the string contains letters, spaces, punctuation, symbols, or has no characters at all.
string.isdecimal(). It takes no arguments and returns a boolean (True or False).
It returns False. An empty string has no decimal characters, so isdecimal() is always False for "".
No. "3.14".isdecimal() and "-5".isdecimal() both return False because "." and "-" are not decimal digits. isdecimal() checks each character individually, not whether the whole string parses as a float.
Both require all characters to be digit-like and the string to be non-empty. isdecimal() is stricter: it allows only characters that can form base-10 numbers (like 0-9 and Arabic-Indic digits). isdigit() also accepts some compatibility characters such as superscript digits, which isdecimal() rejects.
No. isdecimal() only inspects the string and returns a boolean. The original string stays unchanged.