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 字串