How to print of value of i in one line by for loop

2k views Asked by At

I write this code:

for i in range(0,7):
     print(i) 

so simply the output will be:

1
2
3
4
5
6

But i want to print like this:

1 2 3 4 5 6

how can I print this output like that.??

2

There are 2 answers

0
anon On BEST ANSWER

You can do the following in Python3. If you want more information check out the documentation on the print function here. And you can read about the unpacking operator here.

print(*list(range(0, 7)), sep = " ")
0
sehafoc On

1) make a string first, then print it

" ".join([str(i) for i in range(0, 7)])

2) Duplicate answer How to print with out a new line

You should Google these things first...