#只要是检测到一个非汉字字符就返回 #if条件一大堆,肯定有更简单的写法,再学吧! def is_ch(word): for ch in word: if not('u4e00' <= ch <= 'u9fef') and not ('u3400' <= ch <= 'u4db5') and not ('u20000' <= ch <= 'u2a6d6') and not ('u2a700' <= ch <= 'u2b734') and not ('u2b740' <= ch <= 'u2b81d') and not ('u2b820' <= ch <= 'u2cea1') and not ('u2ceb0' <= ch <= 'u2ebe0') and not ('u2f00' <= ch <= 'u2fd5') and not ('u2e80' <= ch <= 'u2ef3') and not ('uf900' <= ch <= 'ufad9') and not ('u2f800' <= ch <= 'u2fa1d') and not ('ue815' <= ch <= 'ue86f') and not ('ue400' <= ch <= 'ue5e8') and not ('ue600' <= ch <= 'ue6cf') and not ('u31c0' <= ch <= 'u31e3') and not ('u2ff0' <= ch <= 'u2ffb') and not ('u3105' <= ch <= 'u312f') and not ('u31a0' <= ch <= 'u31ba'): return False break return True3. 有时间时可以扩展
(1)比如:全部为汉字时返回True和原字符串,有非汉字时返回False和非汉字字符串。
(2)if中判断条件一大堆,肯定有简单的写法,找到一个简单的写法或是优雅点的写法。
(3)更简单的实现方法?这些Unicode 编码连续吗?找时间研究一下!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)