Trying to print
Numbers are: 1 2 3 4 5
from here
numbers = [1,2,3,4,5]
print("Numbers are: "),
for n in numbers:
print(n),
But it doesn't print numbers in same line, it prints them on new line, why? I am on Python 3.
Trying to print
Numbers are: 1 2 3 4 5
from here
numbers = [1,2,3,4,5]
print("Numbers are: "),
for n in numbers:
print(n),
But it doesn't print numbers in same line, it prints them on new line, why? I am on Python 3.
In python 3.x
you have to use print(..., end =" ")
to substitute the new line with an empty space for example.
numbers = [1,2,3,4,5]
print("Numbers are: ", end =" ")
for n in numbers:
print(n, end =" ")
use :
print(n, end=" ")
because:
Python’s print() function comes with a parameter called ‘end’. By default, the value of this parameter is ‘\n’, i.e. the new line character.