Python String isdigit() Method


Contents

Description

The isdigit() method in Python String checks whether the string consists of digits only. In Python strings, isdigit() method is again inbuilt and is utilized for handling strings. The isdigit() method in Python is supposed to return True when all characters found in the string are digits, else, It would return False.

Syntax

Here is the syntax for isdigit() method:

str.isdigit()

Parameters

  • NA

Return Value

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

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()

When we run above program, it produces following result

True
False

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.



Navigation
Tutorial
Tutorial
Tutorial