[英]Can not print on same line in python. Neither print(“string here”, end = “”) nor does print “something”, work
I want to print multiple statements on the same line in python 3.7. 我想在python 3.7的同一行上打印多个语句。 I have tried both using the print " string"
, and print("Something",end = " ")
but neither work. 我已经尝试使用print " string"
和print("Something",end = " ")
两者,但是都没有用。 Both give syntax errors. 两者都给出语法错误。
print 'Checkout: ',
Gives 给
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Checkout: ', end=" ")
Ironically when using: 具有讽刺意味的是,使用时:
print('Checkout: ', end = " ")
I get a red line under the = " " part saying unexpected expression syntax.
在=“”部分下出现红线,表示unexpected expression syntax.
Edit: The problem was that the IDE was essentially running in 2.* mode. 编辑:问题是IDE本质上在2. *模式下运行。 Even though there was a red line under the end = " " part it compiled and ran fine. 即使在“ =”部分的末尾有一条红线,它也会编译并运行良好。
Well, in Python 3.* the print "Checkout"
isn't going to work because Python 3.* requires the parenthesis. 好吧,在Python 3. *中,由于Python 3. *需要括号,所以print "Checkout"
将不起作用。 If you would like to print multiple statements on the same line you could try something like this, 如果您想在同一行上打印多个语句,可以尝试这样的操作,
print("Checkout: , Tax: , Balance: ")
If you are interested in placing values in the blank spots then, perhaps you could try this, 如果您有兴趣将值放在空白处,那么也许可以尝试一下,
print("Checkout: {0}, Tax: {1}, Balance: {2}".format(100, 0.8, 100.8))
I hope this helps. 我希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.