注册 登录
编程论坛 Python论坛

不知道s=b'hello'什么意思,在这请教各位

tanjianyong 发布于 2011-12-16 11:00, 938 次点击
s=b'hello world'
谁能告诉我b' '的作用是什么,谢谢
1 回复
#2
wynemo2012-07-15 22:08
http://
根据这里的回答python2.6之前没有 b''这种写法 2.6,2.7中这种写法和普通的''没区别

而在3.x中 b''的意思是 Bytes literals, 是python 3的新类型

根据这里的说法的话 http://www.

Motivation
    Python's current string objects are overloaded.  They serve to hold
    both sequences of characters and sequences of bytes.  This
    overloading of purpose leads to confusion and bugs.  In future
    versions of Python, string objects will be used for holding
    character data.  The bytes object will fulfil the role of a byte
    container.  Eventually the unicode type will be renamed to str
    and the old str type will be removed.

看上去想把2.x中的str的byte容器功能给这个bytes类型   而unicode类型将取代str类型  原有的str类型将被移除

也就是 比如说以前在2.x 写某些网络程序时 发送字节序 'exit\r\n'
现在在3.x中要这样写 b'exit\r\n'
1