encode Python · 字符串方法
把字符串按指定编码转成字节串。
怎么用
字符串.encode(编码='utf-8')
小例子
print('你好'.encode('utf-8'))
运行结果
b'\xe4\xbd\xa0\xe5\xa5\xbd'
官方文档:https://docs.python.org/zh-cn/3/library/stdtypes.html#string-methods
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条