这只是我的代码的一部分:print("Total score for %s is %s ", name, score)但我希望它打印出来:“(姓名)的总分是(分数)”其中name是列表中的变量,score是整数。如果有帮助的话,这就是Python 3.3。
3 回答

慕雪6442864
TA贡献1812条经验 获得超5个赞
使用方法.format():
print("Total score for {0} is {1}".format(name, score))
要么:
// Recommended, more readable code
print("Total score for {n} is {s}".format(n=name, s=score))
要么:
print("Total score for" + name + " is " + score)
要么:
`print("Total score for %s is %d" % (name, score))`
添加回答
举报
0/150
提交
取消