Python isdecimal() Method

Python 字符串Python Strings


Description

Python isdecimal() method checks whether the string contains only decimal characters. This method exists only on Unicode objects.

Note:To define a decimal string, simply add the 'u' prefix before the string.

Syntax

Syntax of isdecimal() method:

str.isdecimal()

Parameters

  • None

Return Value

Returns True if the string contains only decimal characters, otherwise returns False.

Example

The following example demonstrates the usage of the isdecimal() function:

#!/usr/bin/python


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

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

The output of the above example is as follows:

False
True

Python 字符串Python Strings

Other Extensions