1.string轉bytes
s = 'hello world!' #'hello world!'
#方法一
b = bytes(s,encoding='utf8') #需要指定編碼格式
#方法二
b=s.encode('utf8')
2.bytes轉string
#b:b'hello world!'
#方法一
s = str(b,'utf8')
#方法二
s = b.decode() # 第一參數默認utf8,第二參數默認strict
1.string轉bytes
s = 'hello world!' #'hello world!'
#方法一
b = bytes(s,encoding='utf8') #需要指定編碼格式
#方法二
b=s.encode('utf8')
2.bytes轉string
#b:b'hello world!'
#方法一
s = str(b,'utf8')
#方法二
s = b.decode() # 第一參數默認utf8,第二參數默認strict
繼續運行 ?* 回憶上次內容 上次使用shell環境中的命令 命令 作用 c