Python Forum

Full Version: printing sideways
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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 = '')
Ah, that's what it is. That works great. Thanks.