In [8]: b=b'hello'

In [9]: type(b)
Out[9]: builtins.bytes

In [10]: s='hello'

In [11]: type(s)
Out[11]: builtins.str

To convert from str to bytes, use str.encode().:

In [12]: a=str.encode(s)

In [13]: type(a)
Out[13]: builtins.bytes

To convert from bytes to str, use bytes.decode():

In [14]: c=bytes.decode(a)

In [15]: type(c)
Out[15]: builtins.str

相关文章:

  • 2021-12-23
  • 2022-12-23
  • 2021-09-06
  • 2022-01-20
  • 2021-07-15
  • 2021-11-19
猜你喜欢
  • 2021-10-14
  • 2022-02-13
  • 2022-12-23
  • 2021-12-03
  • 2021-05-30
  • 2021-07-26
相关资源
相似解决方案