python字符串str和字节数组相互转化方法

作者:jingxian 时间:2022-02-14 08:31:48 

实例如下:


# 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)
标签:字符串,字节数组,python
0
投稿

猜你喜欢

  • 网站发布后Bootstrap框架引用woff字体无法正常显示的解决方法

    2023-08-13 00:26:58
  • php获取访问者IP地址汇总

    2023-11-14 12:14:06
  • js 实现数值的千分位及保存小数方法(推荐)

    2023-08-17 01:13:11
  • Go语言集成开发环境之VS Code安装使用

    2023-08-29 13:06:38
  • 微信公众号开发之获取位置信息php代码

    2023-11-17 06:33:15
  • CentOS7中使用shell脚本安装python3.8环境(推荐)

    2022-08-24 17:04:24
  • MySQL表设计优化与索引 (三)

    2010-10-25 20:05:00
  • CSS自定义属性Expression

    2011-04-29 14:17:00
  • Web设计中的黄金分割[译]

    2009-02-20 13:41:00
  • 如何制作关联的下拉菜单?

    2010-06-29 21:19:00
  • PHP使用flock实现文件加锁的方法

    2023-10-29 21:26:59
  • 网站有效设计的10个原则

    2008-02-11 17:12:00
  • ASP+Access数据库安全设置方法小结

    2011-04-02 11:09:00
  • SQL Server如何才能访问Sybase中的表

    2009-01-08 13:33:00
  • [译文]The seven rules of Unobtrusive JavaScript

    2008-09-29 12:10:00
  • python脚本定时发送邮件

    2023-08-07 16:36:02
  • python爬取微信公众号文章

    2021-12-30 18:46:35
  • encodeURIComponent用法UrlEncode与URLEncode.encode()

    2009-05-11 12:40:00
  • python Matplotlib数据可视化(2):详解三大容器对象与常用设置

    2022-11-23 21:10:41
  • ASP实现GB2312转UTF-8函数

    2009-02-26 13:08:00
  • asp之家 网络编程 m.aspxhome.com