Latest web development tutorials

Python isnumeric()方法

Python 字符串 Python字符串


描述

Python isnumeric() 方法檢測字符串是否只由數字組成。 這種方法是只針對unicode對象。

注:定義一個字符串為Unicode,只需要在字符串前添加'u'前綴即可,具體可以查看本章節例子。

語法

isnumeric()方法語法:

str.isnumeric()

參數

  • 無。

返回值

如果字符串中只包含數字字符,則返回True,否則返回False

實例

以下實例展示了isnumeric()方法的實例:

#!/usr/bin/python


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

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

以上實例輸出結果如下:

False
True

Python 字符串 Python字符串