Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Miopas
Last active June 25, 2018 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Miopas/5cd67d9e87db359c336de8f12e92d3c0 to your computer and use it in GitHub Desktop.
Save Miopas/5cd67d9e87db359c336de8f12e92d3c0 to your computer and use it in GitHub Desktop.
判断字符串是否包含汉字/是否全是汉字
# 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