网络编程
位置:首页>> 网络编程>> Python编程>> python字符串str和字节数组相互转化方法

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

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

标签:字符串,字节数组,python

实例如下:


# 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)
0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com