Python3 beginner question | Sololearn: Learn to code for FREE!

+1

Python3 beginner question

How come this code results in: [1, 2, 3, 4, 5, 6, 7, 8, 9] I'm trying to convert the list to a string so it prints as: 123456789 What am I doing wrong? https://code.sololearn.com/c981g8TASjle/?ref=app

12/1/2020 12:40:36 AM

Dustin James Locey

2 Answers

New Answer

+8

numbers = list(range(1,10)) print(*numbers, sep='') or numbers = list(range(1,10)) print(''.join([str(i) for i in numbers])) or numbers = list(range(1,10)) print(''.join(map(str,numbers))) or numbers = list(range(1,10)) s = '' for i in numbers: s += str(i) print(s)

+2

Thank you, that makes a lot of sense now lol. I finished java and came here. Its all coming really easily. It is a little different though :)