Python isnumeric() Method

Python 字符串Python String


Description

The Python isnumeric() method checks whether a string consists only of numeric characters. This method is only for Unicode objects.

Note:To define a string as Unicode, simply add the 'u' prefix before the string. For details, see the examples in this chapter.

Syntax

The isnumeric() method syntax:

str.isnumeric()

Parameters

  • None.

Return Value

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

Examples

The following example demonstrates the isnumeric() method:

#!/usr/bin/python

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

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

The output of the above example is:

False
True

Python 字符串Python String

Other Extensions