How do you print without giving 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='>> print["a","b","c"].
a b c..
>>> print["a","b","c",sep=""].

How do I not print the last space in Python?

You're close, just change your print statement from print[[word], end=' '] to print[[word], end=''] . Your print statement has a whitespace for the end but you don't want the whitespace so make the end an empty string.

Chủ Đề