您的当前位置:首页正文

python中isnumeric如何使用

来源:华拓网

说明

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

以上就是python中isnumeric的使用,希望对大家有所帮助。更多Python学习指路:

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