bytearray 字符串转为字节
Posted sea-stream
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bytearray 字符串转为字节相关的知识,希望对你有一定的参考价值。
>>> str="hello world"
>>> x=bytearray(str)
>>> x
bytearray(b‘hello world‘)
>>> x.decode()
u‘hello world‘
>>>bytearray()
bytearray(b‘‘)
>>> bytearray([1,2,3])
bytearray(b‘\x01\x02\x03‘)
>>> bytearray(‘runoob‘, ‘utf-8‘)
bytearray(b‘runoob‘)
>>>
以上是关于bytearray 字符串转为字节的主要内容,如果未能解决你的问题,请参考以下文章
Python bytearray/bytes/string区别