-2

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.??

Rakibul Islam
  • 167
  • 1
  • 2
  • 14

2 Answers2

0

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...

sehafoc
  • 866
  • 6
  • 9
0

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 = " ")
anon
  • 1,258
  • 10
  • 17