我今天已经开始编程了,Python也有这个问题。很蠢,但我不知道怎么做。当我使用print命令时,它会打印我想要的任何内容,然后转到另一行。例如:print "this should be"; print "on the same line"
应返回:this should be on the same line
但结果是:this should be
on the same line
更确切地说,我正试图创建一个程序,它使用if告诉我一个数字是否是2def test2(x):
if x == 2:
print "Yeah bro, that's tottaly a two"
else:
print "Nope, that is not a two. That is a (x)"
但它不会将最后一个(x)识别为输入的值,而是准确地打印出:“(x)”(带括号的字母)。要想成功,我必须写:print "Nope, that is not a two. That is a"; print (x)
如果我输入test2(3),那么:Nope, that is not a two, that is a
3
所以,要么我需要让Python将我在打印行中的(x)识别为数字;要么在同一行上打印两个不同的东西。
提前谢谢你,为这么愚蠢的问题道歉。
重要提示:我使用的是2.5.4版
另一个注意事项:如果我把print "Thing" , print "Thing2"放在第二张打印纸上,它会显示“语法错误”。