Python3 isnumeric()方法

Python3 字符串 Python3 字符串


描述

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

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

語法

isnumeric()方法語法:

str.isnumeric()

參數(shù)

  • 無。

返回值

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

實例

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

#!/usr/bin/python3


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

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

以上實例輸出結(jié)果如下:

False
True

Python3 字符串 Python3 字符串