python字符串与二进制之间的转换

#字符串与二进制之间的转换
#encode   字符串转为二进制
#decode   二进制转为字符串
#str   字符串
#bytes    二进制
wo = "你好"
print(wo)
print(type(wo))#打印数据类型
print(wo.encode(encoding="utf-8"))
print(type(wo.encode(encoding="utf-8")))#打印数据类型
print(wo.encode(encoding="utf-8").decode(encoding="utf-8"))
#输出结果
你好
<class 'str'>
b'\xe4\xbd\xa0\xe5\xa5\xbd'
<class 'bytes'>
你好

发布了38 篇原创文章 · 获赞 0 · 访问量 270

猜你喜欢

转载自blog.csdn.net/weixin_44654782/article/details/104409154