Ofek .T.
Ofek .T.

Reputation: 762

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.

Upvotes: 4

Views: 179

Answers (2)

Volatility
Volatility

Reputation: 32300

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.

Upvotes: 10

jamylak
jamylak

Reputation: 133554

>>> import sys
>>> sys.stdout.write('hel');sys.stdout.write('lo')
hello

Upvotes: 3

Related Questions