bytes与str转化

it2024-10-07  40

msg="我爱北京天安门" print(msg)

输出:我爱北京天安门

print(msg.encode(encoding="utf-8")) # str转bytes,编码

output: b’\xe6\x88\x91\xe7\x88\xb1\xe5\x8c\x97\xe4\xba\xac\xe5\xa4\xa9\xe5\xae\x89\xe9\x97\xa8’

print(msg.encode(encoding="utf-8").decode(encoding="utf-8")) # bytes转str,解码

output: 我爱北京天安门

最新回复(0)