Python 的 str.isnumeric()
方法返回 boolean
指示字符串中的所有字符是否都是數字。
注意
數字字符包括數字字符以及具有Unicode數值屬性(屬性值Numeric_Type = Digit
、Numeric_Type = Decimal
或Numeric_Type = Numeric
)的所有字符。這包括下標、上標、分數、羅馬數字和貨幣分子。
參數
無參數。
返回值
單個 boolean
指示字符串中的所有字符是否都是數字。
例子
數字
檢查'123'
中的所有字符是否都是數字:
a = '123'
a.isnumeric()
True
檢查'\u00B2123'
中的所有字符是否都是數字:
b = '\u00B2123'
b.isnumeric()
True
True
請注意,'\u00B2123'
是 '²123'
的 Unicode,因此我們返回 True
。
檢查'\u00BD'
中的所有字符是否都是數字:
c = '\u00BD'
c.isnumeric()
True
True
請注意,'\u00BD'
是 '½'
的 Unicode,因此我們返回 True
。
非數字
檢查'123A'
中的所有字符是否都是數字:
d = '123A'
d.isnumeric()
False
False
由於'A'
不是數字字符,因此返回False
。
相關用法
- Python String isnumeric()用法及代碼示例
- Python String isalnum()用法及代碼示例
- Python String isidentifier()用法及代碼示例
- Python String isprintable()用法及代碼示例
- Python String isalnum方法用法及代碼示例
- Python String isalpha方法用法及代碼示例
- Python String isspace()用法及代碼示例
- Python String istitle方法用法及代碼示例
- Python String isspace方法用法及代碼示例
- Python String isprintable方法用法及代碼示例
- Python String isdecimal()用法及代碼示例
- Python String isdigit方法用法及代碼示例
- Python String isdigit()用法及代碼示例
- Python String isupper()用法及代碼示例
- Python String isalpha()用法及代碼示例
- Python String isdecimal方法用法及代碼示例
- Python String istitle()用法及代碼示例
- Python String islower方法用法及代碼示例
- Python String islower()用法及代碼示例
- Python String isascii方法用法及代碼示例
- Python String isidentifier方法用法及代碼示例
- Python String isupper方法用法及代碼示例
- Python String index()用法及代碼示例
- Python String index方法用法及代碼示例
- Python String count方法用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 Python String | isnumeric method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。