Python String isdigit() Method With Example

Python String isdigit

Now, we are going to learn about the isdigit method. If we are required to check whether or not, all the characters in the string are digits, we can make use of the isdigit method. The method returns True if all the characters in the string are digits, and False otherwise. Let’s have a look at an example, which tries to demonstrate the same thing.

Python String isdigit() Method

As you can see, in the above program, there is a string, where all the characters in the string are digits. So, we are going to get True as an output in this case. But if there are any characters in the string, which are not digits, then it is going to return False. Now, Let’s have a look at the case when all the digits in the string are not digits. Let’s have a look at the below program, which demonstrates the same thing.

As you can see in the above program, we have a string, and then we are trying to find if all the characters in the string are digits or not. The output from the isdigit method is False this time since all the characters in the string are not digits.

So, at times, whenever we are required to check if all the characters in the string are digits or not, then we can simply make use of the isdigit method. Remember that this method returns True, or False, depending on whether or not all the characters in the string are digits.