encode 和 decode 的使用

txt = '我是字符串'
txt_encode = txt.encode()
print(txt)
# 我是字符串
print(txt_encode)
# b'xe6x88x91xe6x98xafxe5xadx97xe7xacxa6xe4xb8xb2'
print(type(txt))
# <class 'str'>
print(type(txt_encode))
# <class 'bytes'>
txt_copy = txt_encode.decode( )
print(txt_copy)
# 我是字符串
print(type(txt_copy))
# <class 'str'>

# str->bytes encode
# bytes->str decode

2020-05-07

原文地址:https://www.cnblogs.com/hany-postq473111315/p/12845094.html