Latest web development tutorials

Python3 isnumeric()方法

Python3 字符串 Python3字符串


描述

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

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

語法

isnumeric()方法語法:

str.isnumeric()

參數

  • 無。

返回值

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

實例

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

#!/usr/bin/python3


str = "w3big2016"  
print (str.isnumeric())

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

以上實例輸出結果如下:

False
True

Python3 字符串 Python3字符串