美文网首页
python str与bytes之间的转换

python str与bytes之间的转换

作者: tkpy | 来源:发表于2018-07-10 10:43 被阅读0次
     1 # bytes object  
     2 b = b"example"
     3 
     4 # str object  
     5 s = "example"  
     6 
     7 # str to bytes  
     8 sb = bytes(s, encoding = "utf8")  
     9 
    10 # bytes to str  
    11 bs = str(b, encoding = "utf8")  
    12 
    13 # an alternative method  
    14 # str to bytes  
    15 sb2 = str.encode(s)  
    16 
    17 # bytes to str  
    18 bs2 = bytes.decode(b)
    

    相关文章

      网友评论

          本文标题:python str与bytes之间的转换

          本文链接:https://www.haomeiwen.com/subject/hpkfpftx.html