参考链接:https://blog.csdn.net/anlian523/article/details/80504699

参考链接:https://www.cnblogs.com/chownjy/p/6625299.html

 

python3中,字符串的存储方式都是以Unicode字符来存储的,所以前缀带不带u,其实都一样。

字符串(str)编码(encode) 之后就是 二进制流(b’’)

方法:s1=bytes(s11,encoding='gbk') 指定编码格式,

      s='how to use'.encode('utf-8')

二进制流(b’’) 解码(decode)之后就是 字符串(str)

方法:s2=str(s1.decode('gbk'))

      s3=s1.decode('gbk')

样例:

s11='中国'
s1=bytes(s11,encoding='gbk')
print(type(s1))
print(s1)
s2=str(s1.decode('gbk'))
print(type(s2))
print(s2)
s3=s1.decode('gbk')
print(type(s3))
print(s3)

s4='how to use'.encode('utf-8')
print(type(s4))
print(s4)
s5=s4.decode('utf-8')
print(type(s5))
print(s5)

结果:

python3 编码

结论:可以看出汉字用二进制流表示时,显示出来的是\x 形式的 而英文则不同

 

相关文章:

  • 2022-03-04
  • 2021-05-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
猜你喜欢
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2021-06-03
  • 2021-04-24
  • 2021-11-05
相关资源
相似解决方案