python返回汉字首字母示例
对python这个高级语言感兴趣的小伙伴,下面一起跟随编程之家 52php.cn的小编两巴掌来看看吧!
def get_first_letter(char): char=char.encode('GBK')
if char<b"xb0xa1" or char>b"xd7xf9": return "" if char<b"xb0xc4": return "a" if char<b"xb2xc0": return "b" if char<b"xb4xed": return "c" if char<b"xb6xe9": return "d" if char<b"xb7xa1": return "e" if char<b"xb8xc0": return "f" if char<b"xb9xfd": return "g" if char<b"xbbxf6": return "h" if char<b"xbfxa5": return "j" if char<b"xc0xab": return "k" if char<b"xc2xe7": return "l" if char<b"xc4xc2": return "m" if char<b"xc5xb5": return "n" if char<b"xc5xbd": return "o" if char<b"xc6xd9": return "p" if char<b"xc8xba": return "q" if char<b"xc8xf5": return "r" if char<b"xcbxf9": return "s" if char<b"xcdxd9": return "t" if char<b"xcexf3": return "w" if char<b"xd1x88": return "x" if char<b"xd4xd0": return "y" if char<b"xd7xf9": return "z" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |