python3 isnumeric()方法
描述
isnumeric() 方法检测字符串是否只由数字组成,数字可以是: unicode 数字,全角数字(双字节),罗马数字,汉字数字。
指数类似 ² 与分数类似 ½ 也属于数字。
# s = '½' s = 'u00bd'
语法
isnumeric()方法语法:
str.isnumeric()
参数
- 无。
返回值
如果字符串中只包含数字字符,则返回 true,否则返回 false
实例
以下实例展示了 isnumeric() 方法的实例:
实例
#!/usr/bin/python3
str = "51frw2016"
print (str.isnumeric())
str = "23443434"
print (str.isnumeric())
str = "51frw2016"
print (str.isnumeric())
str = "23443434"
print (str.isnumeric())
以上实例输出结果如下:
false true
unicode 数字:
实例
#!/usr/bin/python3
#s = '²3455'
s = 'u00b23455'
print(s.isnumeric())
# s = '½'
s = 'u00bd'
print(s.isnumeric())
a = "u0030" #unicode for 0
print(a.isnumeric())
b = "u00b2" #unicode for ²
print(b.isnumeric())
c = "10km2"
print(c.isnumeric())
#s = '²3455'
s = 'u00b23455'
print(s.isnumeric())
# s = '½'
s = 'u00bd'
print(s.isnumeric())
a = "u0030" #unicode for 0
print(a.isnumeric())
b = "u00b2" #unicode for ²
print(b.isnumeric())
c = "10km2"
print(c.isnumeric())
以上实例输出结果如下:
true true true true false
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!