How to print without line feed in Python?

Python Methods and Functions

print ( " geeks " )

print ( "pythonengineering" )

will lead to this

 geeks pythonengineering 

But sometimes it may happen that we do not want to go to the next line, but want to print on the same line. So what can we do? 
For example :

 Input: print ("geeks") print ("pythonengineering") Output: geeks pythonengineering Input: a = [1, 2, 3, 4 ] Output: 1 2 3 4 

The solution discussed here depends entirely on the version of Python you are using.

Printing without line feed in Python 2. x

# Python 2 printable code
# on the same line print
# geeks and gixforgix
# on the same line

 

print ( "geeks" ),

print ( "pythonengineering" )

< code class = "undefined spaces">  
# array

a = [ 1 , 2 , 3 , 4 ]

 
# print the element in the same
# line

for i in range ( 4 ):

print (a [i]), 

Output:

 geeks pythonengineering 1 2 3 4 
< p align = center> Printing without line feeds in Python 3.x

# Python 3 printable code
# on the same print line
# geeks and gixforgix
# on the same line

  

print ( "geeks" , end = " " )

print ( "pythonengineering" )

 
# array

a = [ 1 , 2 , 3 , 4 ]

 
# print the element in the same
# line

for i in range ( 4 ):

print (a [i], end = ""

Output:

 geeks pythonengineering 1 2 3 4 




Tutorials