如何在Python中获取中文字拼音的首个字母

  介绍

如何在Python中获取中文字拼音的首个字母?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

<强>代码如下:

def  single_get_first (unicode1):=,,str1  unicode1.encode (& # 39; gbk # 39;)   ,试一试:   ,奥德(str1)   ,return  str1.decode (& # 39; gbk # 39;)   ,除了:=,,asc  str1 [0], *, 256, +, str1[1],安康;65536   ,if  asc 祝辞=,-20319,以及asc  & lt;=, -20284:   ,return  & # 39;一个# 39;   ,if  asc 祝辞=,-20283,以及asc  & lt;=, -19776:   ,return  & # 39; b # 39;   ,if  asc 祝辞=,-19775,以及asc  & lt;=, -19219:   ,return  & # 39; c # 39;   ,if  asc 祝辞=,-19218,以及asc  & lt;=, -18711:   ,return  & # 39; d # 39;   ,if  asc 祝辞=,-18710,以及asc  & lt;=, -18527:   ,return  & # 39; e # 39;   ,if  asc 祝辞=,-18526,以及asc  & lt;=, -18240:   ,return  & # 39; f # 39;   ,if  asc 祝辞=,-18239,以及asc  & lt;=, -17923:   ,return  & # 39;舌鳎# 39;   ,if  asc 祝辞=,-17922,以及asc  & lt;=, -17418:   ,return  & # 39; h # 39;   ,if  asc 祝辞=,-17417,以及asc  & lt;=, -16475:   ,return  & # 39;强生# 39;   ,if  asc 祝辞=,-16474,以及asc  & lt;=, -16213:   ,return  & # 39; k # 39;   ,if  asc 祝辞=,-16212,以及asc  & lt;=, -15641:   ,return  & # 39; l # 39;   ,if  asc 祝辞=,-15640,以及asc  & lt;=, -15166:   猴,return  & # 39; # 39;   ,if  asc 祝辞=,-15165,以及asc  & lt;=, -14923:   ,return  & # 39; n # 39;   ,if  asc 祝辞=,-14922,以及asc  & lt;=, -14915:   ,return  & # 39; o # 39;   ,if  asc 祝辞=,-14914,以及asc  & lt;=, -14631:   ,return  & # 39; p # 39;   ,if  asc 祝辞=,-14630,以及asc  & lt;=, -14150:   ,return  & # 39;提问# 39;   ,if  asc 祝辞=,-14149,以及asc  & lt;=, -14091:   ,return  & # 39; " # 39;   ,if  asc 祝辞=,-14090,以及asc  & lt;=, -13119:   ,return  & # 39; & # 39;   ,if  asc 祝辞=,-13118,以及asc  & lt;=, -12839:   ,return  & # 39; t # 39;   ,if  asc 祝辞=,-12838,以及asc  & lt;=, -12557:   ,return  & # 39; w # 39;   ,if  asc 祝辞=,-12556,以及asc  & lt;=, -11848:   ,return  & # 39; x # 39;   ,if  asc 祝辞=,-11847,以及asc  & lt;=, -11056:   ,return  & # 39; y # 39;   ,if  asc 祝辞=,-11055,以及asc  & lt;=, -10247:   ,return  & # 39; z # 39;   ,return  & # 39; & # 39;         def  getPinyin(字符串):==,if  string 没有:   return 没有一个=,lst 列表(字符串)=,charLst  []   ,for  l  lst拷贝:   ,charLst.append (single_get_first (l))   ,return  & # 39; & # 39; . join (charLst)         if  __name__ ==, & # 39; __main__ # 39;:   ,打印(getPinyin(& # 39;你好& # 39;))

<强>运行结果:

如何在Python中获取中文字拼音的首个字母

看完上述内容,你们掌握如何在Python中获取中文字拼音的首个字母的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!

如何在Python中获取中文字拼音的首个字母