@
longlonglanguage 试了试 chatgpt ,它给写了 python 代码相当 Nice ,就是英文 unicode 的范围你需要删除一些。```Python
#!/usr/bin/python
# Write Python 3 code in this online editor and run it.
char="@"
# 定义语言的 Unicode 范围
unicode_ranges = {
"中文 (CJK Unified Ideographs)": (0x4E00, 0x9FFF),
"中文 (CJK Extension A)": (0x3400, 0x4DBF),
"英文 (Basic Latin)": (0x0000, 0x007F),
"阿拉伯语 (Arabic)": (0x0600, 0x06FF),
"西班牙语 (Latin-1 Supplement)": (0x0080, 0x00FF),
}
def check_language(char):
"""检查字符属于哪个语言范围"""
code_point = ord(char) # 获取字符的 Unicode 编码点
for language, (start, end) in unicode_ranges.items():
if start <= code_point <= end:
return 1
return 0
# 测试
result = check_language(char)
print(result)
```