编码(encode):将Unicode转换为二进制形式(bytes),bytes以b'开头

解码(decode):将二进制形式(bytes)转化为Unicode

python3中字符类型str以Unicode形式存储在计算机内存中,因此只能对str进行编码,而不能对str进行解码

s = '你好'
print(type(s)) #<class 'str'>
print(s) #你好

#对str编码
s_encode=s.encode('UTF-8')
print(type(s_encode)) #<class 'bytes'>
print(s_encode) #b'\xe4\xbd\xa0\xe5\xa5\xbd'

#对bytes解码
s_decode=s_encode.decode('UTF-8')
print(type(s_decode)) #<class 'str'>
print(s_decode) #你好