Python 3 bytes formatting

前端 未结 6 828
情书的邮戳
情书的邮戳 2020-12-05 22:41

In Python 3, one can format a string like:

\"{0}, {1}, {2}\".format(1, 2, 3)

But how to format bytes?

b\"{0}, {1}, {2}\".fo         


        
6条回答
  •  一向
    一向 (楼主)
    2020-12-05 23:13

    I found the %b working best in Python 3.6.2, it should work both for b"" and "":

    print(b"Some stuff %b. Some other stuff" % my_byte_or_unicode_string)
    

提交回复
热议问题