ITPub博客

首页 > IT职业 > IT生活 > python bytes 和 str的互转

python bytes 和 str的互转

IT生活 作者:kalt 时间:2021-09-09 09:04:51 0 删除 编辑
# bytes object  
 b = b"example"  

 # str object  
 s = "example"  

 # str to bytes  
 bytes(s, encoding = "utf8")  

 # bytes to str  
 str(b, encoding = "utf-8")  

 # an alternative method  
 # str to bytes  
 str.encode(s)  

 # bytes to str  
 bytes.decode(b)

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1805/viewspace-2807947/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: strusts2执行流程
请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    121
  • 访问量
    893