python21天打卡Day10-string和bytes互转

python21天打卡Day10-string和bytes互转

a=‘21 python’
b=a.encode(‘utf-8’)#string转为bytes
print(’{},{}’.format(b,type(b)))

c=b’21 python’
d=c.decode(‘utf-8’)
print(’{},{}’.format(d,type(d)))

D:\学习\Python工程\venv\Scripts\python.exe D:/学习/Python工程/practice/test_demo.py
b’21 python’,<class ‘bytes’>
21 python,<class ‘str’>

Process finished with exit code 0