打印在python多个参数 [英] Print multiple arguments in python
问题描述
这只是我的code的片段:
This is just a snippet of my code:
print("Total score for %s is %s ", name, score)
但我想它打印出来:
对(名称)总得分(评分),其中的名字是在一个列表中的变量和得分是一个整数。这是蟒蛇3.3有没有什么帮助的。
but I want it to print out: "Total score for (name) is (score)" where name is a variable in a list and score is an integer. This is python 3.3 if that helps at all.
推荐答案
将它作为一个元组:
print("Total score for %s is %s " % (name, score))
或者使用新型字符串格式化:
Or use the new-style string formatting:
print("Total score for {} is {}".format(name, score))
或者传递值作为参数和打印
将做到这一点:
print("Total score for", name, "is", score)
如果你不想被打印
,修改月
参数自动插入空格:
If you don't want spaces to be inserted automatically by print
, change the sep
parameter:
print("Total score for ", name, " is ", score, sep='')
如果您正在使用Python 2中,你将不能够使用过去两年,因为打印
不是在Python 2.您可以将功能,但是从导入此行为__ __未来
:
If you're using Python 2, you won't be able to use the last two because print
isn't a function in Python 2. You can, however, import this behavior from __future__
:
from __future__ import print_function
这篇关于打印在python多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!