python 中常见字符函数 chr unichr ord函数介绍
来源:互联网 发布:win10怎么安装mysql 编辑:程序博客网 时间:2024/04/30 09:28
chr()函数用一个范围在range(256)内的(就是0~255)整数作参数,返回一个对应的字符。unichr()跟它一样,只不过返回的是Unicode字符,这个从Python 2.0才加入的unichr()的参数范围依赖于你的Python是如何被编译的。如果是配置为USC2的Unicode,那么它的允许范围就是range(65536)或0x0000-0xFFFF;如果配置为UCS4,那么这个值应该是range(1114112)或0x000000-0x110000。如果提供的参数不在允许的范围内,则会报一个ValueError的异常。
ord()函数是chr()函数(对于8位的ASCII字符串)或unichr()函数(对于Unicode对象)的配对函数,它以一个字符(长度为1的字符串)作为参数,返回对应的ASCII数值,或者Unicode数值,如果所给的Unicode字符超出了你的Python定义范围,则会引发一个TypeError的异常。
示例:
>>> chr(65)'A'>>> ord('a')97>>> unichr(12345)u'\u3039'>>> chr(12345)Traceback (most recent call last): File "<stdin>", line 1, in ? chr(12345)ValueError: chr() arg not in range(256)>>> ord(u'\ufffff')Traceback (most recent call last): File "<stdin>", line 1, in ? ord(u'\ufffff')TypeError: ord() expected a character, but string of length 2 found>>> ord(u'\u2345')9029
0 0
- python 中常见字符函数 chr unichr ord函数介绍
- python ord() chr() unichr() 函数
- Python内置函数chr() unichr() ord()
- Python chr() ord() unichr()
- Python的chr()、unichr()、ord()
- python chr()、unichr()和ord()
- python: ord & chr 函数
- python chr()和ord()函数
- python的chr()、unichr()和ord()
- python chr()、unichr()和ord()使用
- chr()、unichr()和ord()
- chr()、unichr()和ord()
- chr()、unichr()和ord()
- python中hex,oct,chr,ord函数讲解
- python中chr()和ord()函数的用法
- python中chr与ord函数的使用
- Python 函数 —— ord(), chr()
- python的chr()和ord()函数
- Apache与Tomcat整合
- checkStyle 错误一览
- android添加菜单按钮
- 四件在我步入职业软件开发生涯那天起就该知道的。。。
- live555从RTSP服务器读取数据到使用接收到的数据流程分析
- python 中常见字符函数 chr unichr ord函数介绍
- spectrogram函数做短时傅里叶分析
- 代码规范工具-Checkstyle使用手册
- BZOJ 2783 JLOI2012 树 DFS
- The Compiler Generator Coco/R
- Java代码规范、格式化和checkstyle检查配置文档
- 提权apache 为root权限
- android 实现在文本内容超过固定宽度可手动左右滚动查看效果
- 系统设计思考