打印的字符串在Python中显示不正确

打印的字符串在Python中显示不正确,python,Python,在Python中,我试图显示st环,但它没有正确显示。我的代码是: print('Critical: '+ brokenFiles + '| number of errors = ',errorCount) 但是,当显示字符串时,它显示为: ('Critical: testoutput.txt .viminfo superoutput.txt Superoutput.txt .splunk output.txt output2.txt | number of errors = ', 7) 我

在Python中,我试图显示st环,但它没有正确显示。我的代码是:

print('Critical: '+ brokenFiles + '| number of errors = ',errorCount)
但是,当显示字符串时,它显示为:

('Critical: testoutput.txt .viminfo superoutput.txt Superoutput.txt .splunk output.txt output2.txt | number of errors = ', 7)
我试着把它设为单引号/双引号,删除逗号会导致代码无法编译,因为errorCount变量是一个整数。我需要做些什么才能让它工作

我希望字符串显示为:

Critical: testoutput.txt .viminfo superoutput.txt Superoutput.txt .splunk output.txt output2.txt | number of errors = 7

更好的做法是使用字符串的格式化方法

在Python 3中:

print('Critical: {}| number of errors = {}' .format(brokenFiles, errorCount))
或者类似的C样式%表示法,用于Python2,它将在Py3中工作,但已被弃用且丑陋:

print('Critical: %s| number of errors = %d' %(brokenFiles, errorCount))

这是蟒蛇2,不是吗?然后尝试不使用括号。您希望它看起来像什么?不要使用JavaScript样式的字符串+字符串+字符串连接。效率很低。如果你只使用内置的,你会有更好的效果,不会因为这样的事情而头疼。上面的文档有点密集,但该页面有一些新旧样式的示例。如果brokenfile是一个列表,则为“”。joinbrokenfile