python str與byte轉換 encode decode

zsdeus133發表於2018-04-30

具體內容可以查python3.6文件

# str to byte
key = "aaa"
r = str.encode(key)
print(type(r))
print(r)

# byte to str
key2 = b"aaa"
r = key2.decode()
print(type(r))
print(r)

輸出:

<class 'bytes'>
b'aaa'
<class 'str'>
aaa

相關文章