Latest web development tutorials

Python isdecimal()方法

Python 字符串 Python字符串


描述

Python isdecimal() 方法檢查字符串是否只包含十進製字符。 這種方法只存在於unicode對象。

注意:定義一個十進製字符串,只需要在字符串前添加'u'前綴即可。

語法

isdecimal()方法語法:

str.isdecimal()

參數

返回值

如果字符串是否只包含十進製字符返回True,否則返回False。

實例

以下實例展示了isdecimal()函數的使用方法:

#!/usr/bin/python


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

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

以上實例輸出結果如下:

False
True

Python 字符串 Python字符串