字符串和bytes形式的转换⽬录
1.bytes类型转化成str的2种⽅式:
字符串数组怎么转成byte第⼀种:
data = b'hello world'
data = str(data,encoding='utf-8')
print(data,type(data))
>>>>>>>>>>>>>>>>>>>>>>>>
hello world <class 'str'>
第⼆种:
data = b'hello world'
s1= data.decode('utf-8')
print(s1,type(s1))
>>>>>>>>>>>>>>>>>>>>>>>>>>
hello world <class 'str'>
2.字符串类型转化成bytes的2种⽅式
第⼀种⽅式:
data = 'hello world'
data = bytes(data,encoding='utf-8')
print(data,type(data))
>>>>>>>>>>>>>>>>>>>>>>>>
b'hello world' <class 'bytes'>
第⼆种⽅式:
data = 'hello world'
data= de('utf-8')
print(data,type(data))
>>>>>>>>>>>>>>>>>>>>>>>>>>
b'hello world' <class 'bytes'>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。