How can we combine multiple print statements per line in Python?



You can combine multiple print statements per line using, in Python 2 and use the end argument to print function in Python 3.

example

Python2.x
print "Hello",
print " world"

Python3.x
print ("Hello", end='')
print (" world")

Output

This will give the output −

Hello world

Another thing you could do is put all the things in an array and call ''.join(array). 

example

arr = ["Hello", "world"]
print(' '.join(arr))

Output

This will give the output −

Hello world
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements