Can I print without a new line or space?

Say I want to print hello using two different print statements. A.

Like:

print "hel" print "lo" 

But python automatically prints a new line, so if we want it to be on the same line, we need to -

 print "hel"**,** 

Here the problem is, it makes a space, and I want it to be connected. Thanks.

+4
source share
2 answers

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 display the result in the interactive interpreter.

The end keyword parameter for the print function indicates what you want to print after the main text. The default value is '\n' . Here we change it to '' so that nothing is printed at the end.

+10
source
 >>> import sys >>> sys.stdout.write('hel');sys.stdout.write('lo') hello 
+3
source

Source: https://habr.com/ru/post/1479716/


All Articles