牛骨文教育服务平台(让学习变的简单)
博文笔记

python str与bytes之间的转换

创建时间:2011-07-14 投稿人: 浏览次数:424
 # 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)

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。