Learn Python – How to print in same line in Python- Basic and advance

The Python’s print() feature is used to print the result or output to the screen. By default, it jumps to the newline to printing the next statement. It has a pre-defined format to print the output. Let’s apprehend the following example.

Example – 1

print("Welcome")  
print("To")  
print("JavaTpoint")  

Output:

Welcome
To
JavaTpoint

Or, we can write the whole statement in single print() function.

print("Welcome To JavaTpoint")  

Output:

Welcome To JavaTpoint

The Python print() characteristic has an argument called end, which prevents leap into the newline. Let’s understand the following example.

Example – 3:

list1 = [10,11,12,13,14,15]  
for i in list1:  
    print(i, end = " ")  

Output:

10 11 12 13 14 15

In the above code, we declared a list and iterated every element using for loop. The print() characteristic printed the first aspect of the listing and then printed the give up fee which we assigned as ‘ ‘ whitespace and it will be printed until the thing of the list.

We can assign any literal to the end. Let’s apprehend the following example.

Example – 4

list1 = [10,11,12,13,14,15]  
for i in list1:  
    print(i,end = "&")  

Output:

10&11&12&13&14&15&