Python 3 - String isdigit() Method


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/python3

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

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

Result

When we run above program, it produces the following result −

True
False
python_strings.htm
Advertisements