【问题标题】:What does percentage sign do in python if not working as a module [duplicate]如果不作为模块工作,百分号在python中会做什么[重复]
【发布时间】:2014-04-18 17:01:04
【问题描述】:
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 和其他百分比在这段代码中做了什么。我了解有关代码的所有其他内容,它的作用等,但我不太了解百分比的作用。我知道它通常用作模数,并会告诉您两个数字之间的余数被除。对此进行澄清将不胜感激。

【问题讨论】:

    标签: python


    【解决方案1】:

    它对字符串进行格式化。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-20
      • 1970-01-01
      • 2017-11-19
      • 1970-01-01
      • 2016-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多