Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to print without new line or space?

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.

like image 635
Ofek .T. Avatar asked Dec 11 '22 15:12

Ofek .T.


1 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 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.

like image 126
Volatility Avatar answered Dec 29 '22 16:12

Volatility