python 2.7到python 3.2字符串格式错误

python 2.7到python 3.2字符串格式错误,python,string,python-2.7,python-3.x,string-concatenation,Python,String,Python 2.7,Python 3.x,String Concatenation,我有一段python代码: args =(12, 45, 7854) 2 result = 123 3 answer = 456 4 print 'Test with data: ', args, ' result: ', result, ' answer: ', answer 现在,当我使用python2.7.3运行它时,我得到了以下结果: Test with data: (12, 45, 7854) result: 123 answer: 456 但当我使用python3

我有一段python代码:

args   =(12, 45, 7854) 
2 result = 123
3 answer = 456
4 print 'Test with data: ', args, ' result: ', result, ' answer: ', answer
现在,当我使用python2.7.3运行它时,我得到了以下结果:

Test with data:  (12, 45, 7854)  result:  123  answer:  456
但当我使用python3.2.3时,我会出现以下错误:

print 'Test with data: ', args, ' failed result: ', result, ' answer: ', answer
                       ^
SyntaxError: invalid syntax
我寻找了连接或格式化该字符串的不同方法,但使用+或%s会产生相同的错误。
任何帮助,请提前感谢。

在py3x中:

print ('Test with data: ', args, ' failed result: ', result, ' answer: ', answer)
在py3x中:

print ('Test with data: ', args, ' failed result: ', result, ' answer: ', answer)

在Python3+中,您需要放置
print()
,因为2+中的print
关键字现在是3+中的
函数


以下是与此相关的问题。

在Python3+中,您需要放置
print()
,因为2+中的print
关键字现在是3+中的
函数

以下是关于这一点的建议