有一点我不明白:这段代码适用于 python3.5,但它在 python3.4 上给了我一个错误:
s='abcd'
s2=b'%s' % s.encode('ascii')
这是错误:
TypeError: unsupported operand type(s) for %: 'bytes' and 'bytes'
知道为什么它起作用python3.5
而不是起作用python3.4
吗?
PEP 461 的Python 3.5 中的 bytes 和 bytearray 添加了对 % 格式的支持:
该 PEP 建议将类似于 Python 2
str
类型的% 格式化操作添加到bytes
和bytearray
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句