python3中string和bytes之间的转换

python3中string和bytes之间的转换

mystr = 'baidu.com'
print(type(mystr)) # <class 'str'>

mybyte = mystr.encode('utf-8')
print(type(mybyte)) # <class 'bytes'>

mybyte_str = mybyte.decode('utf-8')
print(type(mybyte_str)) # <class 'str'>

猜你喜欢

转载自www.cnblogs.com/WebLinuxStudy/p/12692616.html
今日推荐