码迷,mamicode.com
首页 > 编程语言 > 详细

Python 2.x and 3.x string difference

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

标签:ar   使用   for   sp   on   bs   ad   ef   工作   

 

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

标签:ar   使用   for   sp   on   bs   ad   ef   工作   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!