You can use the sep
parameter to get rid of the spaces:
>>> print("a","b","c")
a b c
>>> print("a","b","c",sep="")
abc
I don't know what you mean by "Java style"; in Python you can't add strings to (say) integers that way, although if a
and b
are strings it'll work. You have several other options, of course:
>>> print("a = ", a, ", b = ", b, sep="")
a = 2, b = 3
>>> print("a = " + str(a) + ", b = " + str(b))
a = 2, b = 3
>>> print("a = {}, b = {}".format(a,b))
a = 2, b = 3
>>> print(f"a = {a}, b = {b}")
a = 2, b = 3
The last one requires Python 3.6 or later. For earlier versions, you can simulate the same effect (although I don't recommend this in general, it comes in handy sometimes and there's no point pretending otherwise):
>>> print("a = {a}, b = {b}".format(**locals()))
a = 2, b = 3
>>> print("b = {b}, a = {a}".format(**locals()))
b = 3, a = 2
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…