Python isnumeric()方法
描述
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