Last active
June 25, 2018 04:49
-
-
Save Miopas/5cd67d9e87db359c336de8f12e92d3c0 to your computer and use it in GitHub Desktop.
判断字符串是否包含汉字/是否全是汉字
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# for python2 | |
def is_hanzi(text): | |
return all(u'\u4e00' <= char <= u'\u9fff' for char in text.decode('utf8')) | |
def has_hanzi(text): | |
return any(u'\u4e00' <= char <= u'\u9fff' for char in text.decode('utf8')) | |
# for python3 | |
def has_hanzi(text): | |
return any('\u4e00' <= ch <= '\u9fff' for ch in text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment