Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
printing sideways
#1
I'm trying to print things out in a line but obviously missing something.
For the code

a = 5
print(f'{a} [');
for x in range(1, 11) :
    print(f'{x}, ')
print(']')
it prints

5 [
1, 
2, 
3, 
4, 
5, 
6, 
7, 
8, 
9, 
10, 
]
How do I get it to print like this

5 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
If this is already answered somewhere let me know. TIA
Reply
#2
The print function automatically adds a new line after whatever text is passed to it. Changing this is done with the end parameter:

print(f'{x}, ', end = '')
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Ah, that's what it is. That works great. Thanks.
Reply


Forum Jump:

User Panel Messages

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