format:格式化方法。由於它知識上是使用了str的__format__方法。python
所謂格式化方法,就是能夠先創建一個輸出字符串的模板,而後用format來填充模板的內容。git
>>> #先作一個字符串模板 >>> template = "My name is {0}. My website is {1}. I am writing {2}." >>> #用format依次對應模板中的序號內容 >>> template.format("hiekay","hiekay.github.io","python") 'My name is hiekay. My website is hiekay.github.io. I am writing python.'
固然,上面的操做若是你要這樣作,也是能夠的:github
>>> "My name is {0}. My website is {1}. I am writing {2}.".format("hiekay","hiekay.github.io","python") 'My name is hiekay. My website is hiekay.github.io. I am writing python.'
除了能夠按照對應順序(相似佔位符了)填充模板中的位置以外,還能夠用關鍵字來指明所應該填寫的內容。web