首页 > 技术文章 > [Python] Python 获取中文的首字母 和 全部拼音首字母

wukong1688 原文

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

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

推荐阅读