[Python] Python 获取中文的首字母 和 全部拼音首字母

 

Python 获取中文的首字母 和 全部拼音首字母

 

代码如下:

import pinyin

def getStrAllAplha(str):
    return pinyin.get_initial(str, delimiter="").upper()
    
def getStrFirstAplha(str):
    str=getStrAllAplha(str)
    str=str[0:1]
    return str.upper()
    

str = '你好在哪来'

print(getStrAllAplha(str))
print(getStrFirstAplha(str))

 

输出:

NHZNL

N

 

本博客地址: wukong1688

本文原文地址:https://www.cnblogs.com/wukong1688/p/11149049.html

转载请著名出处!谢谢~~

posted @ 2019-07-08 04:18  wukong1688  阅读(6631)  评论(0编辑  收藏  举报