import pinyin.cedict

# 转拼音
# nǐhǎo
print(pinyin.get(\'你好\'))  

# ni hao
print(pinyin.get(\'你好\', format="strip", delimiter=" "))  

# ni3hao3
print(pinyin.get(\'你好\', format="numerical"))  

# 获取首字母 n h
print(pinyin.get_initial(\'你好\'))  

# 转英文
# [\'you (informal, as opposed to courteous 您[nin2])\']
print(pinyin.cedict.translate_word(\'\'))  

# [\'Hello!\', \'Hi!\', \'How are you?\']
print(pinyin.cedict.translate_word(\'你好\'))

# [[\'你\', [\'you (informal, as opposed to courteous 您[nin2])\']], [\'你好\', [\'Hello!\', \'Hi!\', \'How are you?\']], [\'好\', [\'to be fond of\', \'to have a tendency to\', \'to be prone to\']]]
print(list(pinyin.cedict.all_phrase_translations(\'你好\'))) 

#获取首字母并转为大写 Z
print(pinyin.get_initial("张一")[0].upper())  

 

版权声明:本文为nicole-zhang原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/nicole-zhang/p/10489839.html