What is isdecimal() in Python?

The isdecimal() function in Python tells whether a string contains all numeric characters.

Syntax

The syntax of the isdecimal() method is as follows:

string.isdecimal()

Parameters

The isdecimal() method does not take any parameters.

Return value

isdecimal() returns a boolean value. If the string contains all decimal characters, the function returns True. Otherwise, it returns False.

Code

In the code below, the isdecimal() function returns False when the string contains either all alphabet or alphanumeric characters. However, in the case of a complete numeric string, the method returns True.

# contains all numbers
num = "12345"
print(num.isdecimal())
# contains all alphabets
alpha = "abcdef"
print(alpha.isdecimal())
# contains both alphabets and numbers
alphanum = "abc34de78"
print(alphanum.isdecimal())
New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources