0x00

你喜欢哪一种方式进行格式化输出?

0x01

  • %s
In [1]: "hello %s" % "world"
Out[1]: 'hello world'

参数化(不知道这样叫合不合适)

In [2]: vari = dict(name="ronething",title="python format")
In [3]: "for %(name)s %(title)s" % vari                                                                                         
Out[3]: 'for ronething python format'
  • format()
In [7]: 'hello {}'.format('world')
Out[7]: 'hello world'
In [10]: "for {name} {title}".format(**vari)
Out[10]: 'for ronething python format'

索引

In [11]: "{0} {2} {1}".format("python","java","golang")
Out[11]: 'python golang java'
  • F'' or f''
In [13]: welcome = "hello world"                  
In [14]: F"for {welcome}"   
Out[14]: 'for hello world'

0x02

封面出处:https://www.pixiv.net/member_illust.php?mode=medium&illust_id=72798502