Skip to main content
 首页 » 编程设计

python-3.x之如何在Python 3中检查汉字是简体还是繁体

2025年01月19日30bhlsheji

我想知道有什么方法可以在 Python 3 中检查汉字是简体中文还是繁体中文?

请您参考如下方法:

cjklib不支持 Python 3。在 Python 3 中,您可以使用 hanzidentifier .

import hanzidentifier 
 
print(hanzidentifier.has_chinese('Hello my name is John.')) 
》 False 
 
print(hanzidentifier.has_chinese('Country in Simplified: 国家. Country in Traditional: 國家.')) 
》 True 
 
print(hanzidentifier.is_simplified('John说:你好!')) 
》 True 
 
print(hanzidentifier.is_traditional('John說:你好!')) 
》 True