logo

Python String Isdecimal() Method


Show

Description

The isdecimal() method in Python checks if the string consists of only specific decimal characters. This method in Python string is thus present only on specific Unicode objects. The isdecimal()- method in Python is a function that returns true in case all the characters within a string are decimal. If each character in the string is not decimal then it would return false.

Note - In order to define a string as Unicode, one shall simply prefixes a 'u' to the assignment of the opening quotation mark. Below is the example.

Syntax

Here is the syntax for isdecimal() method:

str.isdecimal()

Parameters

  • NA

Return Value

This method in Python string is supposed to return true if in case all characters in the string are decimal, else it would return false.

Example

The following example below shows the usage of isdecimal() method.

#!/usr/bin/python

str = u"this2009";  
print str.isdecimal();

str = u"23443434";
print str.isdecimal();

When the above program is run, it produces the following result:

False
True

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