首页 > 编程语言 > 详细

Python 2.x and 3.x string difference

时间:2014-10-30 18:40:43      阅读:201      评论:0      收藏:0      [点我收藏+]

 

In Python 3 unicode strings are the ‘regular strings‘ (str) and byte strings are separate objects.

Low level I/O can be done only with data (byte strings), not text (sequence of characters). For Python 2.x str was also the ‘binary data‘ type. In Python 3 it is not any more and one of the special ‘data‘ objects should be used. Objects are pickled to such byte strings. If you want to enter them manually in code use the "b" prefix (b"XXX" instead of "XXX").

bytes和string并不是毫无关系的,bytes对象有一个decode()方法,向该方法传递一个字符编码参数,该方法会返回使用该种编码解码后的字符串。同样的,string有一个encode()方法,完成反向的工作。

Python 2.x and 3.x string difference

原文:http://www.cnblogs.com/AlexBai326/p/4063172.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!