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.

Live Demo
#!/usr/bin/python

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

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

When we run above program, it produces following result −

True
False

python_strings.htm

Advertisements