I have a simple problem with python about new line while printing. How can I print without newline or space? In python
\n newline or a space. But in this situation we do not will use
append string to
We generally prefer Python 3 in our posts but there are some people who uses python2 too so in this situation we will provide python2 way solution. We will import
sys and use
stdout.write functions and
flush given data to the stdout without a newline.
import sys sys.stdout.write('asdf') sys.stdout.flush()
Another way is if we are using python2.6 and above we can use python3 solution like below.
Python 3 provides simple and convenient solution for this issue.
end parameter is used to specify the line end character. We will set
end option to nothing and this will remove default
\n or end of line or space.
print('this is a string', end="") print(' and this is on the same line')
Another way to remove spaces in multiple print argument is using
sep option of the
print("Hi","Poftut") #Hi Poftut print("Hi","Poftut",sep='') #HiPoftut
5 thoughts on “Python, How To Print Without Newline or Space?”
NONE OF THIS WORKED!!!!!!
A very interesting case where we implement all of the steps we are using in our tutorials.
Have a nice day.
Depends on what you are wanting to accomplish.
Kindly provide use case and code you have assembled.