Python String isdigit() Method

Advertisements


Description

The method isdigit() checks whether the string consists of digits only.

Syntax

Following is the syntax for isdigit() method:

str.isdigit()

Parameters

  • NA

Return Value

This method returns true if all characters in the string are digits and there is at least one character, false otherwise.

Example

The following example shows the usage of isdigit() method.

#!/usr/bin/python

str = "123456";  # Only digit in this string
print str.isdigit();

str = "this is string example....wow!!!";
print str.isdigit();

Let us compile and run the above program, this will produce the following result:

True
False



Advertisements
Advertisements