首页 > 文章列表 > python中isnumeric如何使用

python中isnumeric如何使用

Python isnumeric
230 2022-08-07

说明

1、判断字符串是否只由数字(支持罗马数字、汉字数字等)组成。

2、如果字符串只由数字组成,则返回True,否则返回False。

不仅支持 Unicode 数字、还支持全角数字(双字节)、罗马数字以及汉字数字

实例

str1 = u'mr12468'
print(str1.isnumeric())  # False
str1 = u'12468'
print(str1.isnumeric())  # True
str1 = u'ⅠⅡⅣⅦⅨ'
print(str1.isnumeric())  # True
str1 = u'㈠㈡㈣㈥㈧'
print(str1.isnumeric())  # True
str1 = u'①②④⑥⑧'
print(str1.isnumeric())  # True
str1 = u'⑴⑵⑷⑹⑻'
print(str1.isnumeric())  # True
str1 = u'⒈⒉⒋⒍⒏'
print(str1.isnumeric())  # True
str1 = u'壹贰肆陆捌uuu'
print(str1.isnumeric())  # False

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。