在Python中我们是对 Bytes
(字节类型)进行加密, 所以我们进行加密的时候,要保证是对字节进行操作。
如果是字符串要通过encode进行编码,转换为字节类型。
str
--------encode-------->Bytes
Bytes
----------decode-------->str
实例
\\encode默认编码形式为utf
str1='你好'
str2='hello world'
bytes1=str1.encode()
bytes2=str2.encode()
str3=bytes1.decode()
str4=bytes2.decode()
print(bytes1)
print(bytes2)
print(str3)
print(str4)
output
b'\xe4\xbd\xa0\xe5\xa5\xbd'
b'hello world'
你好
hello world
b’hello world’是Python输出时将自动字节转换成易于用户读的形式(体贴?)