2024-04-20 03:27:56 发布
网友
python 3.x中的print有问题
print
如果您还记得python 2.x中的代码,可以编写如下代码:
var = 224 print "The var is %d" %(var)
它会打印出来:
The var is 224
但在Python3.x中它不起作用,所以谁知道请帮忙。
var = 224 print("The var is %d" % var)
当然必须将print视为Python 3的一个函数。 试试看:http://ideone.com/U95q0L
对于更简单的解决方案,您也可以不使用插值来执行以下操作:
print("The var is", var)
也包括在Ideone上。
在Python 2中,print是print语句中使用的关键字。在Python 3中,print是一个函数名,与任何其他函数一样使用。
尤其是,print需要在其参数列表周围加上括号:
print ("The var is %d" %(var))
参考号:http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function
当然必须将print视为Python 3的一个函数。 试试看:http://ideone.com/U95q0L
对于更简单的解决方案,您也可以不使用插值来执行以下操作:
也包括在Ideone上。
在Python 2中,
print
是print语句中使用的关键字。在Python 3中,print
是一个函数名,与任何其他函数一样使用。尤其是,
print
需要在其参数列表周围加上括号:参考号:http://docs.python.org/3.0/whatsnew/3.0.html#print-is-a-function
相关问题 更多 >
编程相关推荐