How do you print two variables without space in python?

It's the comma which is providing that extra white space.

One way is to use the string % method:

print 'Value is "%d"' % [value]

which is like printf in C, allowing you to incorporate and format the items after % by using format specifiers in the string itself. Another example, showing the use of multiple values:

print '%s is %3d.%d' % ['pi', 3, 14159]

For what it's worth, Python 3 greatly improves the situation by allowing you to specify the separator and terminator for a single print call:

>>> print[1,2,3,4,5]
1 2 3 4 5

>>> print[1,2,3,4,5,end='

Chủ Đề