在Python 3中,可以格式化字符串,如下所示:
"{0}, {1}, {2}".format(1, 2, 3)但是如何格式化字节呢?
b"{0}, {1}, {2}".format(1, 2, 3)引发AttributeError: 'bytes' object has no attribute 'format'。
如果字节没有format方法,如何对字节进行格式化或“重写”?
发布于 2020-08-20 17:46:18
对于Python 3.6+,您可以使用以下简洁的语法:
f'foo {bar}'.encode() # a byte stringhttps://stackoverflow.com/questions/15710515
复制相似问题