[Tutor] Printing without a line feed
Krassen Stefanov
krassen at fmi.uni-sofia.bg
Thu Mar 25 03:43:35 EDT 2021
You can use the loop from your example to print all the numbers but the
last one, and then in one final print with defaults to print the last
number only. This should do the job.
Best,
Krassen
On 25.3.2021 г. 8:35, dn via Tutor wrote:
>
> On 25/03/2021 18.29, Phil wrote:
>> Thank you for reading this.
>>
>> I want to print a range of numbers with a space between them but without
>> a space at the end. For instance:
>>
>> for i in range(6):
>> print(i, end=' ')
>>
>> How do I do this without the end space? I've spent hours on this even
>> though I've managed to do what I want not long ago but I cannot remember
>> how I did it. It's very frustrating.
> end= and sep=
> https://docs.python.org/3/library/functions.html#print
>
> NB if there is an end=nullstring within the loop, the cursor remains at
> the end of the 'printed' line.
> Thus, afterwards, another print() will 'end' the line!
>
> Alternately, use the loop to build a string or a list, which can then be
> join-ed with space(s) - and print after the loop terminates.
More information about the Tutor
mailing list