python 字符串和字节串的转换

1、编码(encode)

  字符串转字节串叫编码

    str ------------> bytes

    b = s.encode(encoding='utf-8')

2、解码(decode)

  字节串转字符串叫解码

    bytes ----------> str

    s = b.decode(encoding='utf-8')

posted @ 2020-12-23 18:19  昱成  阅读(521)  评论(0编辑  收藏  举报