只需要将对应的东西,按照顺序在 format 后面的括号中排列好,分别对应占位符 {} 即可:
>>> s1 = “I like {}”.format(“python”)
>>> s1
‘I like python’
>>> s2 = “Beijing is more than {} years. {} lives in here.”.format(2500, “qiwsir”)
>>> s2
'Beijing is more than 2500 years. qiwsir lives in here.'
>>> print “Suzhou is more than {year} years. {name} lives in here.”.format(year=2500, name=”qiwsir”)
Suzhou is more than 2500 years. qiwsir lives in here.