The Python’s print() function 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 understand the following example.
Example - 1
print("Welcome")
print("To")
print("JavaTpoint")
Output:
Welcome
To
JavaTpoint
Or, we can write the complete statement in single print() function.
print("Welcome To JavaTpoint")
Output:
Welcome To JavaTpoint
The Python print() function has an argument called end, which prevents jump 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 each element using for loop. The print() function printed the first element of the list and then printed the end value which we assigned as ’ ’ whitespace and it will be printed till the element of the list.
We can assign any literal to the end. Let’s understand 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&