python 字节数组和字符串的互转

全在程序里了:

byte = b"dingjing"  # 字节数组
strstr = "gaozhen"  # 字符串
# print(type(strstr))

byte2str = byte.decode() # 字节数组转字符串
print(byte2str,type(byte2str))

str2bytes = strstr.encode()  # 字符串转字节数组
print(str2bytes,type(str2bytes))
发布了71 篇原创文章 · 获赞 17 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qionggaobi9328/article/details/99605213