Python3实现汉语转换为汉语拼音

Isabel ·
更新时间:2024-09-21
· 758 次阅读

本文实例为大家分享了Python3实现汉语转换为汉语拼音的具体代码,供大家参考,具体内容如下

工具: Python3.6.2,pycharm

1.使用了 第三方模块 pypinyin(点击File->setting...->Project:name(自己的项目名称)->Project Interpreter)

点击+ ,输入pypinyin,点击 Install Pageage

2. 上代码

import pypinyin # 不带声调的(style=pypinyin.NORMAL) def hp(word): s = '' for i in pypinyin.pinyin(word, style=pypinyin.NORMAL): s += ''.join(i) return s # 带声调的(默认) def hp2(word): s = '' for i in pypinyin.pinyin(word): s = s + ''.join(i) + " " return s if __name__ == "__main__": print(hp("中国中央电视台春节联欢晚会")) print(hp2("中国中央电视台春节联欢晚会"))

输出结果:

D:\Python\Python36\python.exe D:/pyWorkspace/reptile/chinesePYC.py zhongguozhongyangdianshitaichunjielianhuanwanhui zhōng guó zhōng yāng diàn shì tái chūn jié lián huān wǎn huì Process finished with exit code 0

注:新手上路,本文章仅供参考.

您可能感兴趣的文章:python实现将汉字转换成汉语拼音的库Python 返回汉字的汉语拼音



汉语拼音 Python3 Python

需要 登录 后方可回复, 如果你还没有账号请 注册新账号