Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python打印同一行_Python_Python 3.x - Fatal编程技术网

Python打印同一行

Python打印同一行,python,python-3.x,Python,Python 3.x,如何在没有“\n”和参数的情况下打印 例如: 打印此文件:Print(“%d,%d”%(a,b)) 无换行 我试过这个(但不起作用):print(“%d,%d”%(a,b),end=“”) 我有这个: File "./test.py", line 9 print("%d, %d" % (a, b), end="") ^ SyntaxError: invalid syn

如何在没有“
\n
”和参数的情况下打印

例如:

打印此文件:
Print(“%d,%d”%(a,b))
无换行

我试过这个(但不起作用):
print(“%d,%d”%(a,b),end=“”)

我有这个:

  File "./test.py", line 9
    print("%d, %d" % (a, b), end="")
                                ^                           
SyntaxError: invalid syntax

Python 2.x

from __future__ import print_function   # import the print func
print("{}, {}".format(1, 2), end="")   # 1, 2
print("{}, {}".format(1, 2), end="")   # 1, 2
Python 3.x

from __future__ import print_function   # import the print func
print("{}, {}".format(1, 2), end="")   # 1, 2
print("{}, {}".format(1, 2), end="")   # 1, 2

打印并以特殊字符结尾

print('YOur message',end='')
默认情况下,末尾是
\n
,可以被覆盖

您的消息字符串将是
'{}{}'。格式(a,b)

完成它以
print('a={},b={}'。格式(a,b),end='')


什么不起作用,你有什么错误吗?我有一个语法错误:无效语法你标记了Python 3,但听起来你在使用Python 2。不要为我工作@APoorDev使用
import
尝试第一个,因为它看起来像是在使用Python 2。x@APoorDev对你有用吗?如果它确实有帮助,你可以接受答案:干杯,不要问这个问题