The isdecimal()
function in Python tells whether a string contains all numeric characters.
The syntax of the isdecimal()
method is as follows:
string.isdecimal()
The isdecimal()
method does not take any parameters.
isdecimal()
returns a boolean value. If the string contains all decimal characters, the function returns True
. Otherwise, it returns False
.
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 numbersnum = "12345"print(num.isdecimal())# contains all alphabetsalpha = "abcdef"print(alpha.isdecimal())# contains both alphabets and numbersalphanum = "abc34de78"print(alphanum.isdecimal())