判断是否是数字(中文)

linkaiyi
Follow

如何判断中文字符串是数字

直接使用String.isnumeric()就可以

>>> "一二三壹贰叁123123".isnumeric()
True

判断中文字符串中含有中文数字

可以使用set计算交集的功能

CN_NUM = '零一壹幺二贰两四肆五伍六陆七柒八捌九玖十拾'
if len(set(CN_NUM) & set(instance.name)) > 0:
    try:
        name_str.append(cn2an.transform(instance.name))
    except ValueError:
        name_str.append(instance.name)
else:
name_str.append(instance.name)
Object has 0 attachments

Was this article helpful?

This article is viewed 42 times!

Recent Viewed Articles

Related Articles

0 Comments

Leave a Comment

Support