如果没有作为模块工作,百分号在python中的作用是什么

时间:2014-03-13 18:17:27

标签: python

def getresults(candidates, parties, votes, percentageofvote):
    results = "/=\/=\=/=\=/=\=/=\=/=\Election Results/=\=/=\=/=\=/=\=/=\=/=\=/=\/\n\n Candidate Party   Votes   Percent\n\n\n"
    for x in range(len(candidates)):
        results = results + "%12.12s"%candidates[x] + "\t%3.3s"%parties[x] + "\t%3.3s"% votes[x] + "\t" + str(percentageofvote[x]) + "\n"
    return(results)

所以我的问题是%12.12以及其他百分比在此代码中的作用。我理解代码的所有其他内容,它的功能等,但我不太清楚百分比的作用。我知道通常它作为一个模数工作,并会告诉你两个数字之间的剩余部分。对此的澄清将非常感激。

1 个答案:

答案 0 :(得分:0)

它会对字符串进行格式化。

更多信息: http://docs.python.org/2/library/string.html#format-examples