Python
来源:互联网 发布:win7软件打不开 编辑:程序博客网 时间:2024/05/21 09:59
1.打印所有汉字及其拼音
import pypinyinn = 0for i in range(0x4e00,0x9fa6): print(chr(i),'%-5s'%pypinyin.pinyin(chr(i))[0][0],end = ' ') n += 1 if (n%15 == 0): print()
2.汉字拼音的相互转换
from pypinyin import pinyin,lazy_pinyinimport pypinyin#输入汉字,查询同音字def samechr(): in_chr = input("Please input a chiness character:") n = 0 for i in range(0x4e00,0x9fa6): if(pinyin(chr(i))[0][0] == pinyin(in_chr)[0][0]): print(chr(i),end = ' ') n += 1 if (n%15 == 0): print()#输入拼音,查询同音字 def sametune(): in_pinyin = input("Please input a PinYin(e.g. zhong1):") n = 0 for i in range(0x4e00,0x9fa6): if(pinyin(chr(i), style = pypinyin.TONE3)[0][0] == in_pinyin): print(chr(i),end = ' ') n += 1 if (n%15 == 0): print()#输入字符串,注音def stringtune(): in_str = input("Please input your string:") py = lazy_pinyin(in_str,style = pypinyin.TONE) result = '' for i in range(len(in_str)): result = result + in_str[i]+ py[i] print(result)def main(): while True: print() print("以字查字1;以音查字2;为字符串注音3;退出99") choice = input("Please input your choice:") if (choice == '1'): samechr() elif(choice == '2'): sametune() elif(choice == '3'): stringtune() elif(choice == '99'): break else: print("Please input right choice!!")if __name__ == '__main__': main()
汉字拼音转换工具文档:http://pypinyin.mozillazg.com/zh_CN/master/index.html
Python汉字转换成拼音:http://www.cnblogs.com/code123-cc/p/4822886.html
阅读全文
0 0
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- python
- Python
- 认识各种锁
- 洛谷P1421 小玉买文具
- Respberry pi 安装中文输入法
- 刽子手游戏,紫书P79Uva489
- 导入导出项目到myeclipse中
- Python
- python学习笔记
- SQL性能优化十条经验(转)
- xml,xsl,xpath
- jmeter__time查询前一天或者一个月的时间
- 常用文件和IO类使用总结
- shell
- 块级元素、行级元素、行内块元素
- PAT乙级 1051. 复数乘法 (15)--四舍五入带来的正负号细节问题