Let's say that I want to print 'hello' by 2 different print statements.
Like:
print "hel"
print "lo"
But python automatically prints new line so if we want it in the same line we need to -
print "hel"**,**
Here's the problem - the , makes a space and I want it connected. Thanks.
You can use the print
function
>>> from __future__ import print_function
>>> print('hel', end=''); print('lo', end='')
hello
Obviously the semicolon is in the code only to show the result in the interactive interpreter.
The end
keyword parameter to the print
function specifies what you want to print after the main text. It defaults to '\n'
. Here we change it to ''
so that nothing is printed on the end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With