#πŸ”’ Hi how do i print numbers in a straight line

26 messages Β· Page 1 of 1 (latest)

floral peak
#

im trying to print
for x in range(5):
print(x, sep='')
but in a straight line it prints out
0
1
2
3
4

subtle locustBOT
#

@floral peak

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

placid heath
#

end=''

brittle trout
#

!e

print(*[x for x in range(5)], sep="")
subtle locustBOT
#

@brittle trout :white_check_mark: Your 3.12 eval job has completed with return code 0.

01234
brittle trout
#

@floral peak

leaden canyon
#

or you want end?

#

!e

for x in range(5):
    print(x, end='')
subtle locustBOT
#

@leaden canyon :white_check_mark: Your 3.12 eval job has completed with return code 0.

01234
brittle trout
#

depends how much golfing you want

brittle trout
#

it's far more readable

shell flame
#

!e

print(*range(5), end = "")```
subtle locustBOT
#

@shell flame :white_check_mark: Your 3.12 eval job has completed with return code 0.

0 1 2 3 4
brittle trout
#

!e

print("".join([str(i) for i in range(5)]))
subtle locustBOT
#

@brittle trout :white_check_mark: Your 3.12 eval job has completed with return code 0.

01234
brittle trout
#

or without using neither sep or end

sullen wraith
#

!e

print(*range(5), sep='')
print(*range(5))
subtle locustBOT
#

@sullen wraith :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | 01234
002 | 0 1 2 3 4
floral peak
#

tysm everyone

brittle trout
#

npnp

floral peak
#

!close

placid heath
#

πŸ’€ showing golf code to probably beginner that no idea what it do

subtle locustBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.