#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020-10-23 19:34
# @Author : Nuonuo
# @Site :
# @File : str and bytes.py
# @Software: PyCharm
# bytes object
b = b"example"
# str object
s = "example"
# str to bytes
sb = bytes(s, encoding = "utf8")
# bytes to str
bs = str(b, encoding = "utf8")
# an alternative method
# str to bytes
sb2 = str.encode(s)
# bytes to str
bs2 = bytes.decode(b)
bytes和str类型转换
最新推荐文章于 2024-05-17 06:58:51 发布