b'字符串'引发的疑问?

来源:互联网 发布:php posix getpid 编辑:程序博客网 时间:2024/06/02 05:20

问题一

  • python2
    python2.x 中,b 前缀没有具体的意义,只是为了兼容 python3.x 的写法

  • python3
    python3.x 中,默认的 str 是 pyhton2.x 中的 unicode
    python2.x 中的 str是 bytes

问题二

  • unicode 转 bytes
data.encode('utf-8')
  • bytes 转unicode
str(b",'utf-8')