Python String isdecimal() Method With Example

Python String isdecimal() Method With Example

Now, we are going to learn about the isdecimal method. As the name of the method suggests, with the isdecimal method, we can check if all the characters in the string are decimals. The method returns True if all the characters in the string are decimal characters, and otherwise, the method returns False. Let’s have a look at a simple program, which demonstrates the same thing.

Python String isdecimal() Method

As you can see in the program, we have the string, where all the characters are decimal characters. Then we are calling the isdecimal method. This method returns True in this case. Let’s have a look at another case when all the characters in the string are not decimal characters.

As you can see in the program, we have a string, in which, all the characters are not decimal characters. In such a situation, the isdecimal method returns False.

So, as and when required, we can make use of the isdecimal method, to check if all the characters in the string are decimal characters. It returns True, if all the characters in the string are decimal characters, and False otherwise.