zoukankan      html  css  js  c++  java
  • 判断一个字符是否为汉字,英文字母,数字,空还是其他

    # -*- coding: utf-8 -*-
    # @Time    : 18-9-13 下午12:16
    # @Author  : Felix Wang
    
    # 判断一个字符是否为汉字,英文字母,数字,空还是其他
    # 使用Unicode编码来判断
    def is_chinese(uchar):
        """判断一个unicode是否是汉字"""
        if  u'u4e00' <= uchar <= u'u9fa5':
            return True
        else:
            return False
    
    
    def is_number(uchar):
        """判断一个unicode是否是数字"""
        if u'u0030' <= uchar <= u'u0039':
            return True
        else:
            return False
    
    
    def is_alphabet(uchar):
        """判断一个unicode是否是英文字母"""
        if (u'u0041' <= uchar <= u'u005a') or (u'u0061' <= uchar <= u'u007a'):
            return True
        else:
            return False
    
    
    def is_space(uchar):
        """判断一个unicode是否是空字符串(包括空格,回车,tab)"""
        space = [u'u0020', u'u000A', u'u000D', u'u0009']
        if uchar in space:
            return True
        else:
            return False
    
    
    def is_other(uchar):
        """判断是否非汉字,数字,空字符和英文字符"""
        if not (is_space(uchar) or is_chinese(uchar) or is_number(uchar) or is_alphabet(uchar)):
            return True
        else:
            return False
  • 相关阅读:
    awk使用
    SQL VIEW(视图)
    crontab使用
    SecureCRT
    Python异常
    Python字符串
    Python字典,列表,元组
    Python路径
    vim插件
    Python类
  • 原文地址:https://www.cnblogs.com/felixwang2/p/9641379.html
Copyright © 2011-2022 走看看