Printing output on same line and not different lines

When the below code is executed, 

num_list = [1,2,3,4,5]

for i in num_list:
    print(i)

The above statement prints next output on a new line.

The output shall be,
1
2
3
4
5
--------------------------------------------------

However, if the output is a long sequence, the above output is not readable, if we want to print on the same line, then introduce comma after every print which prints the output on the same line. The code now looks like

num_list = [1,2,3,4,5]

for i in num_list:
    print(i),

The output shall be,
1  2  3  4  5

Post a Comment

0 Comments