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 序列 - bytes 和 bytearray

Python bytearray/bytes/string区别

python中的内置函数(bytearray)

bytes, bytearray, 切片, 封装,解构,set,dict知识总结

java中String类型的如何转为byte[]

C# 中字符串string和字节数组byte[]的转换