在两个字符串之间不打印换行符
这个问题在这里已经有了答案:
在第一次print
电话中使用end=''
:
print("Hello", end='')
a = "This is a test"
print(a)
#HelloThis is a test
print
帮助:
print(value, ..., sep=' ', end='n', file=sys.stdout)
Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file: a file-like object (stream); defaults to the current sys.stdout.
sep: string inserted between values, default a space.
end: string appended after the last value, default a newline.
如果您使用的是Python 2.7(有问题的python标签),您可以在打印后放置一个逗号以不返回新行。
print("hello"),
print("world")
将所有的一行打印出“helloworld”。 所以你的情况是这样的:
print("Hello"),
print(a)
或者,如果您使用python 3(python3.x标签)使用:
print("hello", end='')
print('world')
所以你的情况是这样的:
print("Hello", end='')
print(a)
链接地址: http://www.djcxy.com/p/77221.html