<分区>
我在 python 3.x 中遇到 print
问题
如果你还记得 python 2.x,你可以这样写代码:
var = 224
print "The var is %d" %(var)
它会打印出:
The var is 224
但是在 python 3.x 中它不起作用,所以谁知道请帮助。
标签 python python-3.x
<分区>
我在 python 3.x 中遇到 print
问题
如果你还记得 python 2.x,你可以这样写代码:
var = 224
print "The var is %d" %(var)
它会打印出:
The var is 224
但是在 python 3.x 中它不起作用,所以谁知道请帮助。
最佳答案
var = 224
print("The var is %d" % var)
绝对必须将 print 视为 Python 3 的函数。 试试看:http://ideone.com/U95q0L
对于更简单的解决方案,您也可以这样做,无需插值:
print("The var is", var)
也包括在 Ideone 上。
关于python - python 3.x 中使用 % 打印的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19498300/