Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print in For Loop
#1
for i in range(1,9):
   print(i)
result:
Output:
1 2 3 4 5 6 7 8
how i can print this result:
Output:
1 2 3 4 5 6 7 8 
* print numbers in one line.
* i use camma ',' in end of print but not work.  -->  
print(i),
  Think
Reply
#2
Using print(i), would work in Python 2.7. In Python 3.5, you would use print(i, end = ',').
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
for i in range(1, 9):
    print(i, end=' ')
Reply
#4

Thank you for your answer.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation question about input, while loop, then print jamie_01 5 2,615 Sep-30-2021, 12:46 PM
Last Post: Underscore
  why print('\n') produced 2 new lines instead of 1 - Located inside a FOR loop JulyFire 2 2,466 Jan-10-2021, 01:50 AM
Last Post: JulyFire
  Unable to print stuff from while loop Nick1507 4 2,275 Sep-17-2020, 02:26 PM
Last Post: Nick1507
  Print output in single file using pramika loop deepakkhw 1 2,036 Jul-11-2020, 11:57 AM
Last Post: j.crater
  Unable to combine print statements in for loop adeana 2 1,952 Jun-12-2020, 05:08 PM
Last Post: adeana
  Create, assign and print variables in loop steven_tr 10 4,239 May-28-2020, 04:26 PM
Last Post: ndc85430
  Print different positions in loop from functions konsular 5 2,647 Oct-16-2019, 08:10 PM
Last Post: buran
  Python-for loop print into single line dragan979 4 7,006 Nov-23-2018, 01:01 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020