赞
踩
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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。