isdigit() method of str class

The isdigit() method tests whether a string objects is composed only of digits. If all the characters are digits it returns True; Returns False otherwise.

Str Updated 11 Mar 2017 1 min read

Method Name

isdigit

Method Signature

isdigit()

Method Overview

  • The isdigit() method returns True if the string object is solely made of digits.

  • If any character of the string is a non-digit, or if the string is an empty string, isdigit() will return False.

Example

python
# Check a float

piVal       = "3.14"

digitStatus = piVal.isdigit()

print(digitStatus)

# Check an alphanumeric string

testString  = "Formula1"

digitStatus = testString.isdigit()

print(digitStatus)

# Check this is all digits

emirp       = "73"

digitStatus = emirp.isdigit()

print(digitStatus)

Output

Output
False

False

True