首页 > 代码库 > Python 2.x and 3.x string difference
Python 2.x and 3.x string difference
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。