Python中str类型与bytes类型之间的转换

定义一个str型:

a1='simwhale'

定义一个bytes型:

a2=b'simplewhale'

str--->bytes:

b1=bytes(a1,encoding='utf8')

type(b1)

输出结果:bytes


bytes--->str:

b2=str(a2,encoding='utf-8')

type(b2)

输出结果:str


猜你喜欢

转载自blog.csdn.net/weixin_39406669/article/details/79524227