Python 3 bytes formatting

前端 未结 6 824
情书的邮戳
情书的邮戳 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 22:52

    For Python 3.6+ you can use this nice and clean syntax:

    f'foo {bar}'.encode() # a byte string
    

提交回复
热议问题