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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
