Print without a newline between two strings
This question already has an answer here:
Use end=''
in the first print
call:
print("Hello", end='')
a = "This is a test"
print(a)
#HelloThis is a test
Help on 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.
If you are using python 2.7 (python tag on question) you can place a comma after the print to not return a new line.
print("hello"),
print("world")
Will print "helloworld" all one one line. So in your case it will be:
print("Hello"),
print(a)
Or if your using python 3 (python3.x tag on question) use:
print("hello", end='')
print('world')
So in your case it will be:
print("Hello", end='')
print(a)
链接地址: http://www.djcxy.com/p/77222.html
上一篇: 如何在没有空间的情况下打印
下一篇: 在两个字符串之间不打印换行符