實例如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# bytes object b = b "example" # str object s = "example" # str to bytes bytes(s, encoding = "utf8" ) # bytes to str str (b, encoding = "utf-8" ) # an alternative method # str to bytes str .encode(s) # bytes to str bytes.decode(b) |
以上這篇python字符串str和字節數組相互轉化方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。