python字节和字符串相互转换

2019-03-06
笔记

字符串类型

  • byte 字符串
    byte_str = b”byte example”

  • str 字符串
    str_str = “str example”

str to bytes 字符串转字节

1
bytes(str_str, encoding="utf-8")

或

1
str_str.encode()

bytes to str 字节转字符串

1
str(byte_str, encoding="utf-8")

或

1
byte_str.decode()
分享
  • python
  • python 字符串
前一篇
linux使用apt方式安装mysql5.7
后一篇
nohup命令说明
  • 舒克的博客 © 2025
  • Powered by Hexo
  • theme Ocean

舒克的博客
  • 主页
  • 归档
  • 分类
  • 标签
  • 关于
  • 搜索