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

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

原文地址:https://www.cnblogs.com/dengziqi/p/14263296.html