python3输出unicode
2015-11-18 16:41
603 查看
采用ord函数即可
In Python 2.x
Python代码
D:\Python27>python
>>> chr(65)
'A'
>>> ord('A')
65
>>> unichr(20013)
u'\u4e2d'
>>> ord(u'\u4e2d')
20013
>>> ord('中')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ord() expected a character, but string of length 2 found
>>> chr(20013)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: chr() arg not in range(256)
In Python 3.x
Python代码
D:\CODE\PYTHON\OPEN_JUDGE>python
Python 3.2.5 (default, May 15 2013, 23:06:03) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> chr(65)
'A'
>>> ord('A')
65
>>> chr(20013)
'中'
>>> ord('中')
20013
>>> ord('\u4e2d')
20013
In Python 2.x
Python代码
D:\Python27>python
>>> chr(65)
'A'
>>> ord('A')
65
>>> unichr(20013)
u'\u4e2d'
>>> ord(u'\u4e2d')
20013
>>> ord('中')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: ord() expected a character, but string of length 2 found
>>> chr(20013)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: chr() arg not in range(256)
In Python 3.x
Python代码
D:\CODE\PYTHON\OPEN_JUDGE>python
Python 3.2.5 (default, May 15 2013, 23:06:03) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> chr(65)
'A'
>>> ord('A')
65
>>> chr(20013)
'中'
>>> ord('中')
20013
>>> ord('\u4e2d')
20013
相关文章推荐
- Python中list的实现
- Python处理Json报文
- 【python】class之子类
- python 抽象类、抽象方法的实现
- 安装python MySQLdb报错:pymemcompat.h:10:20: 致命错误的解决
- scikit学习心得——Isotonic Regression
- Python编写微信打飞机小游戏(十二)
- Difference between Range and Xrange in Python
- 折腾Ipython
- 第一个Python程序——博客自动访问脚本
- Python基础学习-爬虫小试2
- python插件
- Python学习小记
- 让cherrypy监听系统内所有活动网卡传入的请求
- python 远程操作ubuntu
- Python 创建函数和代码重用
- python数据类型详解
- Python基础练习
- Python pip安装
- python遍历数组的两种方法